国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > WEB開發(fā) > 正文

14.4.使用ActionScript來(lái)進(jìn)行數(shù)據(jù)綁定

2024-04-27 13:52:18
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
14.4.1. 問(wèn)題
我想去通過(guò)ActionScript 而不是MXML 來(lái)創(chuàng)建一個(gè)數(shù)據(jù)綁定。
14.4.2. 解決辦法
使用類mx.utils.binding.BindingUtils 來(lái)創(chuàng)建mx.utils.binding.ChangeWatcher 對(duì)象。
14.4.3. 討論
使用ActionScript 來(lái)創(chuàng)建數(shù)據(jù)綁定,當(dāng)目標(biāo)更新的時(shí)候,可以給你提供更多的可控性。為了使用ActionScript 創(chuàng)建一個(gè)數(shù)據(jù)綁定,使用類BindingUtils 來(lái)創(chuàng)建一個(gè)ChangeWatcher 對(duì)象。

BindingUtils 提供了兩個(gè)靜態(tài)方法,可用于創(chuàng)建數(shù)據(jù)綁定:bindProperty 和bindSetter。

使用方法bindProperty 和BindingUtils 和在MXML 中使用<mx:Binding>標(biāo)記的效果是一致的。

不像使用<mx:Binding>標(biāo)記一樣,有可使用的屬性,需要使用ActionScript 來(lái)進(jìn)行聲明,BindingUtils.bindProperty 的參數(shù)用于定義源和目標(biāo)對(duì)象以及屬性。如下:
+展開
-ActionScript
var watcher:ChangeWatcher = BindingUtils.bindProperty( destination, "property", source, "property" );

通過(guò)方法BindingUtils.bindSetter,你可以聲明函數(shù)來(lái)處理數(shù)據(jù)綁定的源數(shù)據(jù)的更新事件。
+展開
-ActionScript
var watcher:ChangeWatcher = BindingUtils.bindSetter( invalidateProperty, source, "property" );
...
private function invalidateProperty( arg:* ):void
{
// perform any necessary operations.
}

當(dāng)使用了靜態(tài)方法bindProperty 和bindSetter 后,則沒有必要定義變量ChangeWatcher 了。然而,有的時(shí)候你可能需要利用返回的ChangeWatcher 對(duì)象,因?yàn)橥ㄟ^(guò)該對(duì)象,則有可以更新數(shù)據(jù)源、目標(biāo)屬性以及停止數(shù)據(jù)綁定。

接下來(lái)的例子中,使用方法BindingUtils.bindProperty 在控件TextInput 和控件Text 間的text屬性間進(jìn)行了數(shù)據(jù)綁定:
+展開
-XML
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxmllayout="verticalcreationComplete="initHandler();">
<mx:Script>
<![CDATA[
import mx.binding.utils.ChangeWatcher;
import mx.binding.utils.BindingUtils;
private var _nameWatcher:ChangeWatcher;
private function initHandler():void
{
_nameWatcher = BindingUtils.bindProperty( nameField, "text", nameInput, "text" );
}
private function clickHandler():void
{
if( _nameWatcher.isWatching() )
{
_nameWatcher.unwatch();
btn.label = "watch";
}
else
{
_nameWatcher.reset( nameInput );
btn.label = "unwatch";
}
}

]]>
</mx:Script>
<mx:Panel title="User Entry."
paddingLeft="5paddingRight="5"
paddingTop="5paddingBottom="5">

<mx:Form>
<mx:FormItem label="Name:">
<mx:TextInput id="nameInput" />
</mx:FormItem>
</mx:Form>
<mx:HRule width="100%" />
<mx:Label text="You Entered:fontWeight="bold" />
<mx:HBox>
<mx:Label text="First Name:" />
<mx:Text id="nameField" />
</mx:HBox>
<mx:Button id="btnlabel="unwatch"
click="clickHandler();" />

</mx:Panel>
</mx:Application>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 和政县| 吴堡县| 无极县| 桃园县| 综艺| 佛冈县| 万安县| 北流市| 金沙县| 榕江县| 洛川县| 巴马| 五寨县| 石家庄市| 万安县| 长泰县| 若羌县| 两当县| 满洲里市| 习水县| 永安市| 河北省| 临夏市| 翁牛特旗| 仙桃市| 尼木县| 翼城县| 汤原县| 桑植县| 务川| 叶城县| 贡山| 中西区| 涪陵区| 黄梅县| 台州市| 沂南县| 昌黎县| 汾阳市| 明水县| 南乐县|