Flex4数据绑定

<?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/mx" minWidth="955" minHeight="600">
<s:layout>
<s:BasicLayout/>
</s:layout>

<!--使用数据绑定方法一:使用绑定标签绑定,注意使用绑定标签引用组件的使用不用使用大括号-->
<fx:Binding source="myTextInput5.text"
destination="myTextInput6.text"
twoWay="true"/>
<mx:HBox x="0" y="0">
<s:TextInput id="myTextInput5"/>
<s:TextInput id="myTextInput6"/>
</mx:HBox>

<!--不使用数据绑定-->
<s:Group x="0" y="50">
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<s:TextInput id="myTextInput1"/>
<s:Button label="copy:" click="myTextInput2.text = myTextInput1.text;"/>
<s:TextInput id="myTextInput2"/>
</s:Group>



<!--使用数据绑定方法二:直接在属性上引用另一个组件的属性值,注意添加大括号-->
<s:Group x="0" y="80">
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<s:TextInput id="myTextInput3" text="{myTextInput4.text}"/>
<s:Button label="dont click data is binding"/>
<s:TextInput id="myTextInput4" text="{myTextInput3.text}"/>
</s:Group>

<!--使用数据绑定方法3: 绑定Action变量,使用关键字[Bindable]-->

<fx:Script>
<![CDATA[
[Bindable]
public var myString:String="";
]]>
</fx:Script>
<s:Group x="0" y="110">
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<s:TextInput id="myTextInput7"/>
<s:Button label="update my Variable" click="myString=myTextInput7.text"/>
<s:TextInput id="myTextInput8" text="{myString}"/>
</s:Group>

<!--
在真正的应用程序中,会存在各种组件铜鼓绑定监听众多变量。组件会随着数据变化做出反应,但
这些组件却不必关心数据和信息的来源,一种常见的情形时:从外部数据源中取得数据,然后保存在本地
绑定变量中,而相应的视觉组件负责监听这些变量并显示相应的信息。
-->
</s:Application>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值