среда, 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"/>