Data Binding

Flex applications typically utilize lots of data retrieved from both RPCs (server-side method calls) and user input collected in forms. One of the ways in which you can work with data is to use extensive ActionScript. ActionScript provides you with low-level access to all the data in your Flex application. Yet the ActionScript code can be redundant, and it can be time-consuming to write. Although extensive ActionScript may be necessary in some cases, the Flex framework provides a feature called data binding that simplifies working with data in most cases.

Data binding lets you associate data from one object with data from another object. There are lots of ways to use data binding. The following examples list a few of the most common uses for data binding:

  • Link form input controls (text inputs, checkboxes, etc.) with data models.

  • Link two or more controls (e.g., display a slider value in a text component).

In the following sections, we’ll look at the rules of data binding as well as examples of different ways to use data binding.

Understanding Data Binding Syntax

There are three basic ways to apply data binding:

  • Curly brace ({}) syntax

  • <mx:Binding>

  • BindingUtils

Each of these techniques for applying data binding has advantages and disadvantages, which we’ll discuss in the next few sections.

Curly braces

Using curly braces to apply data binding is the simplest and fastest technique. Throughout the early part of this book, you’ve seen quite a few examples of curly brace syntax. Placing ...

Get Programming Flex 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.