Flex 動(dòng)態(tài)綁定BindingUtils.bindProperty
更新時(shí)間:2009年06月11日 22:39:26 作者:
Flex 動(dòng)態(tài)綁定BindingUtils.bindProperty實(shí)現(xiàn)代碼。
關(guān)鍵字:BindingUtils.bindProperty
需導(dǎo)入:import mx.binding.utils.BindingUtils;
/**
* 動(dòng)態(tài)綁定
* @params site:Object 被綁定對(duì)象
* @params prop:String 被綁定對(duì)象的屬性,如textInput的text屬性
* @params host:Object 監(jiān)視者對(duì)象
* @params chain:Object 監(jiān)視者對(duì)象的屬性
* @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>
<!--[CDATA[
import mx.binding.utils.BindingUtils;
import mx.binding.utils.ChangeWatcher;
private var watcher1:ChangeWatcher;
private var watcher2:ChangeWatcher;
/**
* 動(dòng)態(tài)綁定
* @return void
* **/
private function Binding():void {
//綁定ID為txt2的txtInput
//綁定屬性為txtInput的text
//監(jiān)視者ID為txt1的txtInput
//監(jiān)視者屬性為txtInput的text
watcher1 = BindingUtils.bindProperty(txt2,"text",txt1,"text");
//綁定ID為txtComb的txtInput
//綁定屬性為txtInput的text
//監(jiān)視者ID為comb的ComboBox
//監(jiān)視者屬性為ComboBox的value
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="動(dòng)態(tài)綁定" 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>
需導(dǎo)入:import mx.binding.utils.BindingUtils;
/**
* 動(dòng)態(tài)綁定
* @params site:Object 被綁定對(duì)象
* @params prop:String 被綁定對(duì)象的屬性,如textInput的text屬性
* @params host:Object 監(jiān)視者對(duì)象
* @params chain:Object 監(jiān)視者對(duì)象的屬性
* @return ChangeWatcher
* **/
BindingUtils.bindProperty(site:Object,prop:String,host:Object,chain:Object);
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" initialize="init();">
<mx:Script>
<!--[CDATA[
import mx.binding.utils.BindingUtils;
import mx.binding.utils.ChangeWatcher;
private var watcher1:ChangeWatcher;
private var watcher2:ChangeWatcher;
/**
* 動(dòng)態(tài)綁定
* @return void
* **/
private function Binding():void {
//綁定ID為txt2的txtInput
//綁定屬性為txtInput的text
//監(jiān)視者ID為txt1的txtInput
//監(jiān)視者屬性為txtInput的text
watcher1 = BindingUtils.bindProperty(txt2,"text",txt1,"text");
//綁定ID為txtComb的txtInput
//綁定屬性為txtInput的text
//監(jiān)視者ID為comb的ComboBox
//監(jiān)視者屬性為ComboBox的value
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="動(dòng)態(tài)綁定" 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>
相關(guān)文章
Flex與.NET互操作 使用HttpService、URLReqeust和URLLoader加載/傳輸數(shù)據(jù)
在前兩篇文章中分別介紹了Flex與.NET的WebService之間的數(shù)據(jù)交互通信知識(shí),本文將介紹另外一種加載數(shù)據(jù)以及發(fā)起請(qǐng)求的方式。2009-06-06flex 手寫(xiě)在線簽名實(shí)現(xiàn)代碼
企業(yè)信息系統(tǒng)中,有時(shí)候需要用到手寫(xiě)簽名的功能。在這里用flex 實(shí)現(xiàn)一個(gè)。功能實(shí)現(xiàn)了,效果還在改善中。2009-08-08Flex 非常實(shí)用的學(xué)習(xí)資料整理
對(duì)于學(xué)習(xí)flex 的朋友,絕對(duì)是個(gè)不錯(cuò)的一些資料,大家可以用ctrl+F搜索獲取2009-01-01Flex 處理服務(wù)器端傳來(lái)的數(shù)據(jù)
對(duì)于Java端返回的各種Java類(lèi)型的對(duì)象,F(xiàn)lex中能否有相應(yīng)的數(shù)據(jù)類(lèi)型來(lái)映射。這是Flex與服務(wù)器通信使用remoteObject的關(guān)鍵。2009-08-08