Mega Code Archive

 
Categories / Flex / Data Model
 

Data Binding Through the ActionScript BindingUtils Class

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" horizontalAlign="center" verticalAlign="middle" initialize="initComp();">     <mx:Model id="contacts">         <contact>             <name>                 <first />                 <last />             </name>         </contact>     </mx:Model>     <mx:Script>                  import mx.binding.utils.BindingUtils;         private function initComp():void         {             BindingUtils.bindProperty(contacts, "name.first",firstNameInput, "text");             BindingUtils.bindProperty(contacts, "name.last",lastNameInput, "text");             BindingUtils.bindProperty(firstName, "text",contacts, "name.first");             BindingUtils.bindProperty(lastName, "text", contacts,"name.last");         }            </mx:Script>     <mx:Panel title="BindingUtils Class in ActionScript" horizontalAlign="center">         <mx:Form>             <mx:FormItem label="First Name">                 <mx:TextInput id="firstNameInput" />             </mx:FormItem>             <mx:FormItem label="Last Name">                 <mx:TextInput id="lastNameInput" />             </mx:FormItem>             <mx:FormItem label="First Name">                 <mx:Label id="firstName" text="{contacts.name.first}"                     fontSize="15" fontWeight="bold" />             </mx:FormItem>             <mx:FormItem label="Last Name">                 <mx:Label id="lastName" text="{contacts.name.last}"                     fontSize="15" fontWeight="bold" />             </mx:FormItem>         </mx:Form>     </mx:Panel> </mx:Application>