Murat
Murat

Reputation: 35

AS3 Extra Work When Getting/Setting a Property

I don't know if this has a special name or even possible. Consider this code;

public dynamic class Foo {
    public function set (_key:String,_value:*):void {
        this[_key] = _value;
        trace(this[_key] + " property added.");
    }
}

The trace represents some extra work to be done with the property key and/or value. Now we can create any property using the set function.

myFoo.set("prop1",14);
myFoo.set("prop2","test");
etc...

Is there a way to modify this function, so that it will take effect for any property?

myFoo.prop1=14;
myFoo.prop2="test";

I want it to act like a global setter function which takes effect when you create/modify any property of the object. I intend to create a get function in a similar way.

Upvotes: 0

Views: 69

Answers (1)

sberry
sberry

Reputation: 132018

You will need to extend the Proxy class and override setProperty

override flash_proxy function setProperty(_key:*, _value:*):void {
    this[_key] = _value;
    trace(this[_key] + " property added.");
}

Upvotes: 2

Related Questions