ChangeWatcher 用法 ---- import mx.binding.utils.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(personName,"text",person,"text"); 
            ChangeWatcher.watch(personName,"text",nameSetter);  
       } 
       
       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(personName.text); 
       } 

]]> 
</mx:Script> 
    <mx:Panel width="514" height="200" layout="absolute">
        <mx:Label text="txtInp" width="51" x="20" y="10"/>
        <mx:Label text="txt" width="51" x="20" y="38"/>
        <mx:TextInput id="txtInp" width="200"  x="94" y="8"/>
        <mx:Text id="txt" width="200"  x="94" y="38"/>
        <mx:Button label="Bind TextInput to Text" click="bindMe()"  x="83" y="128"/>
        <mx:Button label="Unbind TextInput to Text" click="unbindMe()"  x="260" y="128"/>
        <mx:TextInput id="personName" x="94" y="80" width="126"/>
        <mx:TextInput id="person" x="299" y="80"/>
        <mx:Label text="personName" width="80" x="0" y="82"/>
        <mx:Label text="person" width="49" x="228" y="82"/>
    </mx:Panel>
</mx:Application>

你可能感兴趣的:(function,layout,application,import,button)