Syntax :
ChangeWatcher.watch(object, "property", handler);Whenever the property of the object changes, the handler will respond.
Object – the object which owns the property
"property" – the property you want to watch
handler – the function name of the handler
The property that ChangeWatcher is watching must be [Bindable] and Public.
Sample :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
creationComplete="initApp();">
<mx:Script>
<![CDATA[
import mx.binding.utils.ChangeWatcher;
import mx.controls.Alert;
import mx.events.PropertyChangeEvent;
[Bindable]
public var tmpData:String="welcome";
private function initApp():void
{
ChangeWatcher.watch(this, "tmpData", watchHandler);
}
private function watchHandler(e:PropertyChangeEvent):void
{
// Do Something
}
private function clickHandler():void
{
if (tmpData == "welcome")
tmpData=tmpData.toUpperCase();
else
tmpData=tmpData.toLowerCase();
}
]]>
</mx:Script>
<mx:Label text="{tmpData}"/>
<mx:Button click="clickHandler()"/>
</mx:Application>
No comments:
Post a Comment