<?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"> <s:layout> <s:HorizontalLayout/> </s:layout> <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}"/> <mx:Image/> </s:Application>
【Bindable介绍】
在开发中通常用上Bindable作用在视图控件上,如给它绑定一个对象,则以后只需要在逻辑层更改这个对象的值,则视图层的控件数据会自动更新(同步),而不再需要手动去更新视图。
Bindable允许一个类(或者变量)可以将自身的变化自动通知给感兴趣的对象,当一个对象状态发生改变的时候,所有依赖于他的对象都得到通知并被自动更新。也成为Observer观察者模式。
Bindable是单向的数值链接,事实上Observer模式对应的一个要素就是被观察者对观察者一无所知。
参考 http://blog.csdn.net/yhmhappy2006/article/details/6107080