O'Reilly logo

Programming Flex 2 by Joey Lott, Chafic Kazoun

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Enabling Data Binding for Custom Classes

Data binding is enabled for some types of objects by default, but it won't work for instances of custom classes by default. You must enable data binding with the [Bindable] metatag. The [Bindable] metatag tells the Flex compiler to configure whatever it precedes so that it works with data binding. You can use [Bindable] with the following:

  • A class

  • A property

  • An implicit getter method

  • An implicit setter method

Tip

Note that for data binding to work properly when using implicit getters and setters, you should have both a getter and a setter for every property for which you want to use data binding.

When you use the [Bindable] metatag 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;

When you use [Bindable] before a getter and/or setter method, it marks that getter/setter method as data binding-enabled. If you have both a getter and a setter with the same name, you need to place the [Bindable] metatag before only one of them. If you have only a getter method, the method works only as the source for data binding, and 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";
}

In practical terms, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required