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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access