Follow Flex After Dark on Twitter

[Bindable] Metadata Tag

Flex Binding is a very powerful feature that enables objects and their properties to be bound together.

[Bindable] is a Metadata tag that declares that an object or property can be the source of binding. As the source of a binding an object will dispatch an event (PropertyChangeEvent) when a watched property's value changes.

[Bindable] Example

A bindable property (such as firstName in the below example) will dispatch an event when its value changes.

   [Bindable]
   public var firstName:String;

You can also make an entire class Bindable. Adding [Bindable] above a class declaration makes all the public properties of the class bindable.

[Bindable]
class Contact
{
   // both properties are bindable because the class is tagged bindable
   public var firstName:String;
   public var lastName:String;
   
   ...
}

Custom Binding Events

By default a bindable property will trigger (dispatch) a PropertyChangeEvent named propertyChange.

The [Bindable] tag can also be parameterized with custom event names. This is done by adding a name argument to the Bindable tag: [Bindable(name="customeEventName")].

The below example tags both the firstName and lastName properties to be bindable using a custom event name "nameChange".

   [Bindable(name="nameChange")]
   public var firstName:String;
   
   [Bindable(name="nameChange")]
   public var lastName:String;
   
   
   [Bindable("nameChange")]
   public function get fullName():String
   {
      return this.firstName + " " + this.lastName;
   }

Because firstName, lastName, and fullName are all bindable with the "nameChange" event the change of any one will trigger the appropriate bindable events. So, bindings watching the fullName property will be triggered when the firstName and/or lastName property values are set.

See Binding and Events for more information...

If you view the source of common components we use in MXML you'll see that many of their properties are tagged [Bindable].

Related Links:

Related Docs
  • Flex Metadata Flex Metadata
  • Flex Binding Flex Data Binding enables objects and their values to be bound together so that when a source changes a target automatically gets updated.
Recent Docs
  • ActionScript Bindable ActionScript supports binding via the [Bindable] metadata tag.
  • ActionScript AsyncToken Handling asynchronous requests and results with the AsyncToken class.
  • Flex Date Controls Flex Date Controls allow users to select dates and date ranges with DateField and DateChooser.
  • ActionScript Array The ActionScript Array class and usage examples.
  • Flex Events Events drive Flex applications. See how to register listeners and dispatch events.
Random Docs