Enabling Data Binding for Custom Classes
Data binding is enabled for some types of objects by default, but to
make it work for custom classes, enable data binding with the [Bindable]
metadata tag which tells the
Flex compiler to configure whatever it precedes. Use [Bindable]
with:
A class
A property
An implicit getter method
An implicit setter method
Note
For data binding to work when using implicit getters and setters, you need a getter and a setter for every property that you want to use data binding.
When you use the [Bindable]
metadata tag before a class declaration, it marks all the public
properties and all the getter and setter pairs as
data-binding-enabled:
[Bindable] public class Example {
When you use [Bindable]
before a
property declaration, it sets just that property as
data-binding-enabled:
[Bindable] private var _exampleProperty:String;
When you use [Bindable]
before a
getter and/or setter method, that method becomes data-binding-enabled. If
a getter and setter have the same name, you must place the [Bindable]
metadata tag before only one of them.
If you have only a getter method, the method works only as the source for
data binding. If you have only a setter method, the method works only as
the destination for data binding:
[Bindable] public function get exampleGetter():String { return "example"; }
Always enable both the contents of a custom class and an instance of the class (if instantiated using ActionScript) to use the instance for data binding. Consider the simple class in ...
Get Programming Flex 3 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.