对与触发事件修改控件属性,可以通过:
<fx:Script>
<![CDATA[
private function my_button_clickhandler():void{
my_text.text = "clicked"
}
]]>
</fx:Script>
<s:Label text="Hello" x="100" y="50" id="my_text" />
<s:Button x="100" y="100" id = "my_button" label = "my_button" click="my_button_clickhandler()" />
另外可以通过给属性绑定变量,来达到修改控件属性的目的
<fx:Script>
<![CDATA[
[Bindable]
private var dtext:String = "Hello";
private function my_button_clickhandler():void{
dtext = "clicked"
}
]]>
</fx:Script>
<s:Label text="{dtext}" x="100" y="50" id="my_text" />
<s:Button x="100" y="100" id = "my_button" label = "my_button" click="my_button_clickhandler()" />
这时候就要用到[Bindable](当然元数据 [Bindable]的使用并不仅限于此,有兴趣可以参考:http://gain-loss.org/?p=71 )
实际上这个标识的作用是通知编译器加入绑定事件:使得当变量(dtext)变化时候,所有受其影响的变量都跟着改变。