Hello,

I often need to recognize for some of my gui elemets when the embedded
gui elements (childs) have changed or vice-versa the parent elements
has changed in a property, like "_x", "_width", etc. to repaint the
necessary elements of the GUI.
So what is the best way to do this?

I stumbled over the methods of Object to add or watch properties. This
allows myself to build something like this:

class MyUIObject extends Object
{
        public var _x:Number;

        public function GUIObject() {
                this.addProperty("_x", getX, setX);
                this.watch("_x",onChange,{test: 123}); // possibility 2
        }

        // possibility 2
        private function onChange(prop, oldVal, newVal, userData):Boolean
        {
                if (prop=="_x")
                {
                        onX(newVal);
                        return true;
                } else {
                        return false;
                }
        }       

        private function getX(Void):Number {
                return _x;
        }       
        private function setX(x:Number):Void {
                onX(x); // possibility 1
        }       
        public function onX(x:Number):Void {
        }
}

This way I can set and get _x:

var muo:MyUIObject = new MyUIObject();
trace("1: "+muo._x)
muo._x.onX = function(x)
{
        trace("2: "+this._x);
        trace("3: "+x);
}
muo._x = 100;
trace("4: "+muo._x)

But the onX method is invoked BEFORE _x is actually set, why?
Output:
1: undefined
2: undefined
3: 100
4: 100

Is there a better way to have an onX method, which perhaps is invoked
immediately after _x was set?

Thank you,
Matthias
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to