1,不使用绑定(和html基本一样)
2,使用绑定
3,使用绑定标签
4,使用Actionscript绑定
机制:向textinput中输入数据后,单击update将输入框中的数值赋值给s,然后
text组件会自动显示变量String的值。这个功能非常强大。
[color=darkblue] 注:在真正的应用程序中,会存在各种组件通过监听众多变量的情况(我们在应用程序生命周期的不同号阶段对这些变量进行配置和管理),组件会随着数据变化做出反应,但这些组件却不必关心数据和信息的来源,一种常见的情形是,从外部数据源中取得数据,然后将结果保存在本地绑定变量中;而相应的视觉组件负责监听这些变量并显示相应的信息。[/color]
<?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:HorizontalLayout/>
</s:layout>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:TextInput id="myTextInput1"/>
<s:Button label="copy:" click="myTextInput2.text = myTextInput1.text"/>
<s:TextInput id="myTextInput2"/>
</s:Application>
2,使用绑定
<?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:HorizontalLayout/>
</s:layout>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<!--不使用绑定,通过单击来赋值-->
<s:TextInput id="myTextInput1"/>
<s:Button label="copy:" click="myTextInput2.text = myTextInput1.text"/>
<s:TextInput id="myTextInput2"/>
<!--使用绑定1,可以动态赋值
如果提前知道需要显示绑定什么,这种方法就非常适合,但是,代码变得越来越复杂,您可能想
将元素间的链接作为mxml文件中单独的元素管理。此时最简单的方法就是使用绑定标签
-->
<s:TextInput id="myTextInput3"/>
<s:TextInput id="myTextInput4" text="{myTextInput3.text}"/>
<s:TextInput id="myTextInput5" text="{myTextInput3.text + myTextInput4.text }"/>
</s:Application>
3,使用绑定标签
<?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:HorizontalLayout/>
</s:layout>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Binding source="myTextInput3.text"
destination="myTextInput4.text"
twoWay="true"/>
<s:TextInput id="myTextInput3"/>
<s:TextInput id="myTextInput4"/>
</s:Application>
4,使用Actionscript绑定
机制:向textinput中输入数据后,单击update将输入框中的数值赋值给s,然后
text组件会自动显示变量String的值。这个功能非常强大。
<?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:HorizontalLayout/>
</s:layout>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
[Bindable]
public var s:String = "";
]]>
</fx:Script>
<s:TextInput id="myTextInput1"/>
<s:Button label="Update my variable" click="s=myTextInput1.text"/>
<s:TextInput id="myText" text="{s}"/>
</s:Application>
[color=darkblue] 注:在真正的应用程序中,会存在各种组件通过监听众多变量的情况(我们在应用程序生命周期的不同号阶段对这些变量进行配置和管理),组件会随着数据变化做出反应,但这些组件却不必关心数据和信息的来源,一种常见的情形是,从外部数据源中取得数据,然后将结果保存在本地绑定变量中;而相应的视觉组件负责监听这些变量并显示相应的信息。[/color]