數據綁定的方法
1.在對象的屬性標籤中,使用{}把數據源直接綁定至對象的某個屬性上
2.在對象的屬性標籤中,使用{}把某個函數的返回值作爲數據源綁定對對象屬性上
函數的參數要使用[Bindable]綁定符號
[Bindable]
[Bindable(event="eventname")]
Event表示當數據源發生變化時,數據源所在對象派發的事件類型,它是可選項,默認的事件名是"propertyChange",一
般情況下只需要使用[Bindable]標籤
3.<mx:Model id="books">
<books>
<book>
<name>Flex</name>
<price>120.50</price>
</book>
<book>
<name>FLASH</name>
<price>100.00</price>
</book>
</books>
</mx:Model>
<mx:Binding source="books.book[0].name" destination="txt_name.text"/>
<mx:Binding source="books.book[0].price" destination="txt_price.text"/>
4.動態綁定
Mx.binding.utils
BindingUtils提供了兩個靜態方法處理動態綁定
1)bindProperty(site:Object,prop:String,host:Object,chain:Object,commitOnly:Bollean=false)
參數: site:目標控件
prop:目標屬性
host:數據源控件
chain:數據源控件的屬性
例:BindingUtils.bindProperty(mylabel,"txt",hslider1,"value")
2)bindsetter(setter:Function,host:Object,chain:Object,commitOnly:Boolena=false)
參數: setter:綁定的方法
host:數據源控件
chain:數據源控件的屬性
例: BindingUtils.bindSetter(setTxt,fsize,"value");
internal function setTxt(txt:String):void{
mylabel.text=txt
}