Wednesday, December 30, 2009

Data binding in Flex

Data binding (usually done using {} in mxml) is one of the best features in Flex. It simplifies a lot of coding. Underneath the hood, Flex actually generates a lot of code to handle the data binding.

You can skip the rest of this article and just read Chapter 40 of the Flex Developer Guide.

The easiest way to do data binding is {} in mxml. It is so easy to use and so easy to understand that it is like magic. However, one often has questions about what can or cannot be put into the {}. Object properties (eg. are definitely allowed. Chains like are also allowed. Is functions allowed? Is array allowed? The best source is chapter 40 of the Flex Developer Guide.

To debug {} bindings, see Debugging bindings section in andybryant's blog:

Data binding can be done in many ways:
  1. {} in mxml
  2. <mx:Binding> tag in mxml
  3. BindingUtils class
  4. ChangeWatcher class
  5. good old event listener