Observe Utility

Observe Utility listen’s property changes at run time on any assigned variable and calls its defined function. This utility does the same job as ChangeWatcher or BindingUtils. I prefer using this as its very light weight, fast and handy.

package org.util
{

    /**
     * Detects changes to a value and runs a function in response.
     * @param source: Source value that is to be watched.
     * @param enabled:Prevents ObserveUtil firing before visual elements are available.
     * @param handler: Function that gets called when source property gets changed.
     *
     * @author Chouhan
     *
     */

    public class ObserveUtil
    {
       public var handler:Function;
       public var enabled:Boolean =true;

       public function set source(source:*):void{
           if(enabled){
                handler.call();
            }
        }
    }
}

USAGE:
<util:Observe
 source="{valueThatIsToBeWatchedFor}"
 handler="{valueChangedFunction}" />

 private function valueChangedFunction():void{
     /* Implement your logic upon property change */
 }

Hope you’ve had fun using this utility. !!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s