锁定老帖子 主题:Flex DataBinding(1)
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-09-06
Adobe Flex provides three ways to specify data binding:
1` the curly braces ({}) syntax in MXML, 2` the <fx:Binding> tag in MXML, 3` and the BindingUtils methods in ActionScript.
MXML语言:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768"> <fx:Script> <![CDATA[ import mx.binding.utils.BindingUtils; /** * Use a function to deal with data binding, * when inputText change ,then will call this function * and the function will change the lable2.text */ private function someFunction(_val:String):String { return _val + " receive"; } /** * Binding the Data with the as3 BindingUtils * it define put which object.which param binding where * !!Attaction the first two param is to define which object you want to binding */ public function initDataBinding():void { mx.binding.utils.BindingUtils.bindProperty(lable4, "text", inputText, "text"); } ]]> </fx:Script> <s:TextInput id="inputText" x="22" y="24"/> <mx:Label id="lable1" x="22" y="67" text="{inputText.text.toLocaleUpperCase()}"/> <mx:Label id="lable2" x="24" y="98" text="{someFunction(inputText.text)}"/> <mx:Label id="lable3" x="25" y="132" text="Label"/> <mx:Label id="lable4" preinitialize="initDataBinding()" x="24" y="167" text="Label"/> <fx:Binding source="inputText.text" destination="lable3.text"/> </s:Application>
When data binding occurs:
如果没有在initialize()函数调用时候Trigger的话,Demo中的Label3的Text默认应为“Label3”,但运行结果并非如此
Although binding is a powerful mechanism, it is not appropriate for all situations. For example, for a complex user
MoreInfo: 《Flex4 Help》P362
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
浏览 1730 次