Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


Share this Page URL
Help

Chapter 40: Binding Data - Pg. 1198

1229 Chapter 40: Binding Data Data binding lets you pass data between client-side objects in an Adobe® FlexTM application. Binding automatically copies the value of a property of a source object to a property of a destination object when the source property changes. Topics About data binding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1229 Data binding examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1234 Binding to functions, Objects, and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1236 Using ActionScript in data binding expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1243 Using an E4X expression in a data binding expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1245 Defining data bindings in ActionScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1247 Using the Bindable metadata tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1249 Considerations for using the binding feature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1254 About data binding Data binding is the process of tying the data in one object to another object. It provides a convenient way to pass data between the different layers of the application. Data binding requires a source property, a destination property, and a triggering event that indicates when to copy the data from the source to the destination. An object dispatches the triggering event when the source property changes. Adobe Flex provides three ways to specify data binding: the curly braces ( {} ) syntax in MXML, the <mx:Binding> tag in MXML, and the BindingUtils methods in ActionScript. The following example uses the curly braces ( {} ) syntax to show a Text control that gets its data from a TextInput control's text property: <?xml version="1.0"?> <!-- binding/BasicBinding.mxml --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:TextInput id="myTI" text="Enter text here"/> <mx:Text id="myText" text="{myTI.text}"/> </mx:Application> The property name inside the curly braces is the source property of the binding expression. When the value of the source property changes, Flex copies the current value of the source property, myTI.text , to the destination property, the Text control text property.