Mega Code Archive

 
Categories / Flex / Development
 

Bind to Properties by Using ActionScript

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="initHandler();">     <mx:Script>                      import mx.binding.utils.ChangeWatcher;             import mx.binding.utils.BindingUtils;             private var myChangeWatcher:ChangeWatcher;             private function initHandler():void             {                 myChangeWatcher = BindingUtils.bindProperty( nameField, "text", nameInput, "text" );             }              private function clickHandler():void              {                  if( myChangeWatcher.isWatching() )                  {                      myChangeWatcher.unwatch();                      btn.label = "watch";                  }                  else                  {                      myChangeWatcher.reset( nameInput );                      btn.label = "unwatch";                  }              }            </mx:Script>     <mx:Panel title="User Entry.">           <mx:Form>                  <mx:FormItem label="Name:">                        <mx:TextInput id="nameInput" />                  </mx:FormItem>           </mx:Form>           <mx:Label text="You Entered:" fontWeight="bold" />           <mx:HBox>                <mx:Label text="First Name:" />                <mx:Text id="nameField" />           </mx:HBox>           <mx:Button id="btn" label="unwatch" click="clickHandler();" />     </mx:Panel> </mx:Application>