среда, 3 июня 2009 г.

Data Binding

<mx:Binding source="source.text" destination="destination.text" />
<mx:TextInput id="source" />
<mx:TextInput id="destination" />

OR

<mx:TextInput id="source" />
<mx:TextInput id="destination" text="{source.text}" />

* * *

<mx:Binding source="source.text" destination="destination.text"/>
<mx:Binding source="source2.text" destination="destination.text"/>
<mx:TextInput id="source"/>
<mx:TextInput id="source2"/>
<mx:TextInput id="destination"/>

Simple data binding:

<mx:ComboBox id="c" dataProvider="{myArray}" />
<mx:ViewStack id="v" selectedIndex="{c.selectedIndex}">
<mx:Canvas>
<mx:Label text="1"/>
</mx:Canvas>
<mx:Canvas>
<mx:Label text="2"/>
</mx:Canvas>
</mx:ViewStack>

OR

<mx:ComboBox id="c" dataProvider="{myArray}" />
<mx:Binding source="c.selectedIndex" destination="v2.selectedIndex" />
<mx:ViewStack id="v2">
<mx:Canvas>
<mx:Label text="1"/>
</mx:Canvas>
<mx:Canvas>
<mx:Label text="2"/>
</mx:Canvas>
</mx:ViewStack>

String concatenation:

<mx:TextInput id="fname" />
<mx:TextInput id="lname" />
<mx:Label text="{'First Name: ' + fname.text}" />
<mx:Label text="{'Full Name: ' + fname.text + ' ' + lname.text}" />

OR

<mx:TextInput id="fname" />
<mx:Binding source="{'First Name: ' + fname.text}" destination="destination.text" />
<mx:Label id="destination"/>

Calculations:

<mx:NumericStepper id="quantity" />
<mx:TextInput id="price" />
<mx:Label text="{'Total: ' + quantity.value * Number(price.text)}" />

OR

<mx:NumericStepper id="quantity" />
<mx:TextInput id="price" />
<mx:Binding source="{'Total: ' + quantity.value * Number(price.text)}" destination="destination.text" />
<mx:Label id="destination"/>

Conditional:

<mx:NumericStepper id="quantity" />
<mx:Label text="{(quantity.value % 2) ? 'Odd' : 'Even'}" />

OR

<mx:NumericStepper id="quantity" />

<mx:Binding source="{(quantity.value % 2) ? 'Odd' : 'Even'}" destination="destination.text" />

<mx:Label id="destination"/>

вторник, 28 апреля 2009 г.

cacheAsBitmap для AS2 ручками. AS2

Давно, работая с AS3, убедился, что очень эффективно кэшировать статические мувики вручную - сохранять снимок мувика в BitmapData и заменять на сцене сложный клип на полученное растровое изображение. Выигрыш производительности просто неимоверный! Я даже сделал специальный механизм, который сканировал сцену на предмет таких клипов (помеченных особым именем) и кэшировал их таким способом. Причем, штатный cacheAsBitmap работает совершенно отвратительно и против ручного метода, просто курит в затяг.

И вот, на днях, доделывая одну ужасно тормозную заставку на flash 8, решил применить это дело и для AS2. Вот простейший код, который вставляется во фрейм мувика, на котором мувик надо закешировать (правда внешний контроль над ним будет потерян, но это уже другая история):
import flash.display.BitmapData;
stop();
var bitmap:BitmapData = new BitmapData(this._width,this._height,false);
bitmap.draw(this);
this._parent.attachBitmap(bitmap,this.getDepth());
this.unloadMovie();

среда, 6 августа 2008 г.

Список без подсветки и выделения элементов. Flex

Код к статье Список без подсветки и выделения элементов.
package InterfaceClasses
{
import flash.display.Sprite;
import mx.controls.TileList;
import mx.controls.listClasses.IListItemRenderer;
public class TransparentTileList extends TileList
{
override protected function drawSelectionIndicator(
indicator:Sprite, x:Number, y:Number, width:Number,
height:Number, color:uint,
itemRenderer:IListItemRenderer):void
{
return;
}
override protected function drawHighlightIndicator(
indicator:Sprite, x:Number, y:Number, width:Number,
height:Number, color:uint,
itemRenderer:IListItemRenderer):void
{
return;
}
}
}

вторник, 29 июля 2008 г.

Как наложить цвет на изображение при помощи фильтра

На сцене лежит клип "item".
На него накладывается цвет, к примеру: "0xCC9933FF".


package {
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.filters.ColorMatrixFilter;

public class ColorMatrixFilterExample extends MovieClip {

public function ColorMatrixFilterExample() {
this.applyColor(0xCC9933FF, this.getChildByName("item"));
}

private function applyFilter(child:DisplayObject, matrix:Array):void {
var filter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
var filters:Array = new Array();
filters.push(filter);
child.filters = filters;
}

private function applyColor(rgb:uint,renderer:DisplayObject):void {
var matrix:Array = new Array();

matrix = matrix.concat([((rgb>>24)&0xFF)/0xFF, 0, 0, 0, 0]); // red
matrix = matrix.concat([0, ((rgb>>16)&0xFF)/0xFF, 0, 0, 0]); // green
matrix = matrix.concat([0, 0, ((rgb>>8)&0xFF)/0xFF, 0, 0]); // blue
matrix = matrix.concat([0, 0, 0, ((rgb)&0xFF)/0xFF, 0]); // alpha
applyFilter(renderer, matrix);
}
}
}

четверг, 29 мая 2008 г.

Организация метаданных класса

Информация для статьи Хороший стиль Flex-программирования. Структура файла.

//--------------------------------------
// Events
//--------------------------------------
/
**
* ASDoc comment.
*/
[Event
/**
* ASDoc comment.
*/
[Event
//--------------------------------------
// Styles
//--------------------------------------
/**
* ASDoc comment.
*/
[Style
/**
* ASDoc comment.
*/
[Style]
//--------------------------------------
// Effects
//--------------------------------------
/**
* ASDoc comment.
*/
[Effect
/**
* ASDoc comment.
*/
[Effect]
//--------------------------------------
// Excluded APIs
//--------------------------------------
[Exclude(name="horizontalAlign", kind="style")]
[Exclude(name="verticalAlign", kind="style")]
//--------------------------------------
// Other metadata
//--------------------------------------
[DefaultBindingProperty(source="text", destination="text")]
[IconFile("Text.png")]

среда, 28 мая 2008 г.

Блок Copyright

Информация для статьи Хороший стиль Flex-программирования. Структура файла.


////////////////////////////////////////////////////////////////////////////////
//
// ADOBE SYSTEMS INCORPORATED
// Copyright 2008 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE: Adobe permits you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

среда, 14 мая 2008 г.

Стиль без скина. MXML

.styleName {
skin: ClassReference(null);
}