ChangeWatcher 绑定用法

<?xml version="1.0" ?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.events.PropertyChangeEvent;
     import mx.binding.utils. ChangeWatcher;
     import mx.binding.utils.BindingUtils;
     import mx.controls.Alert;
      
       private var namewatcher: ChangeWatcher;
       private function init():void
       {
    namewatcher = BindingUtils.bindProperty(textArea,"text",person,"text");
    ChangeWatcher.watch(textArea,"text",nameSetter); 
  //  textArea.addEventListener(Event.CHANGE,change); 
  //namewatcher.unwatch();
       }
      
       private function bindMe():void{
         namewatcher = BindingUtils.bindProperty(txt,"text", txtInp,"text");//前面属性跟着后面属性变化
       }
      
       private function unbindMe():void{
               namewatcher.unwatch();           
       }
       private function nameSetter(event:Event):void
       {
       Alert.show(event.toString());
       }
       private function change(event:Event):void
       {
       // Alert.show("changed");
       }
  

]]>
</mx:Script>
<mx:TextInput id="txtInp" width="200" />
<mx:Text id="txt" width="200" />
<mx:Button label="Bind TextInput to Text" click="bindMe()" />
<mx:Button label="Unbind TextInput to Text" click="unbindMe()" />
<mx:TextInput id="textArea"/>
<mx:TextInput id="person"/>
</mx:Application>

你可能感兴趣的:(xml,Adobe)