Flex 动态绑定BindingUtils.bindProperty

<?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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值