Any way to intercept typed function calls in AS3?

I know that this is easy to do with a function dynamically added to a dynamic proxy class, but I would like you to be able to intercept calls to a typed function, for example, using Python decorators. An example is below. I would like to somehow go through "callProperty" for "typedFunc", as if it already goes through "dynFunc",

example

package
{
    import flash.display.Sprite;
    [SWF(width = '400', height = '400')]
    public class Test extends Sprite
    {
        public function Test()
        {
            var t:TypeTest = new TypeTest();
            t.dynFunc = function dynFunc(s:String, i:int):Boolean { return true; };

            t.typedFunc("a", 1);
            t.dynFunc("b", 2);
        }
    }
}
import flash.utils.Proxy;
import flash.utils.flash_proxy;

internal dynamic class TypeTest extends Proxy
{
    private var customs:Object = new Object();
    override flash_proxy function callProperty(name:*, ...parameters):* {
        var retval:* = (this[name] as Function).apply(null, parameters);
        trace("called", name, "with", parameters);
        return retval;
    }
    public function typedFunc(s:String, i:int):Boolean {
        return false;
    }
    override flash_proxy function getProperty(name:*):* { return customs[name]; }
    override flash_proxy function setProperty(name:*, value:*):void { customs[name] = value; }
}
+3
source share
1 answer

This is not easy to do in ActionScript, because the compiler will not allow you to change the method of the private class at runtime using the "normal" ActionScript language constructs, so you cannot change the behavior of the original class. Period.

, as3commons: bytecode. - : AVM, , . , , , .

+2

All Articles