<?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>
Flex4数据绑定
最新推荐文章于 2021-05-26 07:22:35 发布