Saturday, September 3, 2011

Flex :: Metadata tag - Bindable

The [Bindable] metadata tag enables Flex to copy the value of source property to any destination property, when any changes are made to source property.

The [Bindable] metadata tag has following syntax:

[Bindable]
[Bindable ("eventName")]

The [Bindable ("eventName")] metadata tag register the source property with Flex and dispatches event eventName when property is changed. If eventName is omitted, Flex automatically creates an event named propertyChange so that the property can be used as the source of a data binding expression

Example:


[Bindable]
public var audioLevel:uint = 50;

[Bindable ("nameChanged")]
public function get name():String
{
   return myName;
}

public function set name( val:String ):void
{
   myName = val;
   dispatchEvent(new Event( "nameChanged" ) );
}

There are some situation where data binding does not execute automatically

  • When an item of dataprovider is modified.
  • When a sub-property of a property that have [Bindable] metadata tag is modified.
  • When a [Bindable] metadata tag is associated with a property that Flash player updates automatically, such as mouseY.

There are some method that helps to execute binding that do not occur as expected.

  • The executeBindings() method of UIComponent class helps to execute all the binding for which UIComponent is destinated.
  • The executeChildBindings() method of Container and Repeater classes of Flex executes all the binding for which child UIComponent of Container or Repeater class are destinated.

The executeChildBindings() method updates user interface after making changes that does not cause binding to execute.

However, it should be noted that above method should be called only when binding do not executed automatically.



1 comment:

  1. How do we use executeChildBindings for spark contianers?

    ReplyDelete