Pages

Monitoring Object state change with ChangeWatcher.watch

On occasion watching for the change of state in an object can be tricky. A whole series of variables come into play when doing this. One very slick way to monitor and get updates about the change in state of an object is to use the Changewatcher class. By definition "* The ChangeWatcher class defines utility methods that you can use with bindable Flex properties. These methods let you define an event handler that is executed whenever a bindable property is updated."(Adobe Actionscript 3.0 documentation). The method in question is the watch() method, it watches for changes in a [Bindable] variable or method and fires an event when there is a change. This is of great use when the change is random and the time of change indeterminate. To use it you

1. import mx.binding.utils and set a [Bindable property]
import mx.binding.utils

[Bindable]
public var __getcurrentstate:String;


2. set up the ChangeWatcher.watch method
ChangeWatcher.watch(this, '__getcurrentstate', watchcurrentstate);

3 set up the event listener method, in this case the watchcurrentstate method
public function watchcurrentstate(e:Event):void
{
Logger.info('Watched::::::::::::: ', __getcurrentstate);
}

Now if the __getcurrentstate value gets changed. you will be notified by watchcurrentstate.

aYo Binitie II

No comments:

Instagram