
106 Binding
The <mx:Binding> tag must be a top-level
tag
In Flex 1.5, you could place the <mx:Binding> tag in a Flex container. In Flex 2.0, the
<mx:Binding> tag must be a top-level tag in the MXML file. For example:
Flex 1.x:
<mx:HBox>
<mx:Label id="myLabel"/>
<mx:Label id="my2ndLabel" text="hello"/>
<mx:Binding source="my2ndLabel.text" destination="myLabel.text"/>
</mx:HBox>
Flex 2:
<mx:Binding source="my2ndLabel.text" destination="myLabel.text"/>
<mx:HBox>
<mx:Label id="myLabel"/>
<mx:Label id="my2ndLabel" text="hello"/>
</mx:HBox>
Binding from a property
To make properties usable as the source for a data binding expression in Flex 2, you use the
[Bindable] metadata tag. Properties of custom components often have getter/setter pairs
that were tagged with a
[ChangeEvent] metadata tag. For Flex 2, you convert that tag to
[Bindable] and update the setter to dispatch an Event object.
This section describes these processes.
Binding from all public properties in a class
To make all public properties in a class usable as the source for a data binding expression,
properties defined as properties and properties defined by using both a setter and a getter
method, add the
[Bindable] metadata tag before the class statement:
[Bindable]
public class MyClass { ... }
Although the easiest way to migrate an application that uses binding is to make all public
properties in a class support data binding, it is not necessarily the best practice to use the
[Bindable] metadata tag on an entire class. Doing this causes the compiler to generate more
code, which in turn can affect performance and increase your application’s file size.
Comentários a estes Manuais