数据绑定的方法
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
}