Flex 監聽 變量與屬性

監聽變量變化
<?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"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.binding.utils.ChangeWatcher;
import mx.controls.Alert;
import mx.events.FlexEvent;
[Bindable]
public var aaa:String="123";
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
ChangeWatcher.watch(this,"aaa",nnnn);
aaa="789";
}
public function nnnn(event:Event):void
{
Alert.show(aaa);
}
]]>
</fx:Script>
</s:Application>
----------------------------------------------------------------------------------------
監聽控件屬性變化
<?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"  
creationComplete="application1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.binding.utils.ChangeWatcher;
import mx.controls.Alert;
import mx.events.FlexEvent;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
ChangeWatcher.watch(personName,"text",nnnn);
}
public function nnnn(event:Event):void
{
Alert.show(personName.text);
}
]]>
</fx:Script>
<s:TextInput id="personName" text="123"></s:TextInput>
</s:Application>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章