Flex 动态绑定BindingUtils.bindProperty

来源:互联网 发布:淘宝哪家店女装质量好 编辑:程序博客网 时间:2024/05/17 06:24

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
layout="absolute" initialize="init();"> 

<mx:Script> 
import mx.binding.utils.BindingUtils; 
import mx.binding.utils.ChangeWatcher; 


private var watcher1:ChangeWatcher; 
private var watcher2:ChangeWatcher; 

/** 
*
动态绑定 
* @return void 
* **/ 
private function Binding():void { 

//
绑定IDtxt2txtInput 
//
绑定属性为txtInputtext 
//
监视者IDtxt1txtInput 
//
监视者属性为txtInputtext 
watcher1 = BindingUtils.bindProperty(txt2,"text",txt1,"text"); 

//
绑定IDtxtCombtxtInput 
//
绑定属性为txtInputtext 
//
监视者IDcombComboBox 
//
监视者属性为ComboBoxvalue 
watcher2 = BindingUtils.bindProperty(txtComb,"text",comb,"value"); 


/** 
*
解除绑定 
* @return void 
* **/ 
private function UnBinding():void { 
//
解除绑定 
watcher1.unwatch(); 
watcher2.unwatch(); 

</mx:Script> 

<mx:ApplicationControlBar dock="true"> 
<mx:Button label="
动态绑定" click="Binding();"/> 
<mx:Button label="
解除绑定" click="UnBinding();"/> 
</mx:ApplicationControlBar> 



<mx:VBox width="200" height="200"> 

<mx:Spacer height="30"/> 

<mx:TextInput id="txt1"/> 
<mx:TextInput id="txt2"/> 

<mx:Spacer height="30"/> 

<mx:ComboBox id="comb"> 
<mx:dataProvider> 
<mx:Array> 
<mx:String>Beijing</mx:String> 
<mx:String>Shanghai</mx:String> 
<mx:String>Hangzhou</mx:String> 
</mx:Array> 
</mx:dataProvider> 
</mx:ComboBox> 

<mx:TextInput id="txtComb"/> 
</mx:VBox> 
</mx:Application>

原创粉丝点击