关键字:BindingUtils.bindProperty
需导入:import mx.binding.utils.BindingUtils;
/**
* 动态绑定
* @params site:Object 被绑定对象
* @params prop:String 被绑定对象的属性,如textInput的text属性
* @params host:Object 监视者对象
* @params chain:Object 监视者对象的属性
* @return ChangeWatcher
* **/
BindingUtils.bindProperty(site:Object,prop:String,host:Object,chain:Object);
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" initialize="init();">
<mx:Script>
<>
</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>