AS3 arguments

前端 未结 3 1920
北海茫月
北海茫月 2021-01-14 22:47

Why do you think the code below does not work? What would you change/add to make it work?

Any help is appreciated..

function TraceIt(message:String,         


        
3条回答
  •  孤街浪徒
    2021-01-14 23:22

    Ok, here is the solution.. after breaking my head : )

        function TraceIt(message:String, num:int)
        {
            trace(message, num);
        }
    
        function aa(f:Function=null, ...args):void
        {
            var newArgs:Array = args as Array;
            newArgs.unshift(f);
            bb.apply(null, newArgs);
        }
    
        aa(TraceIt, "test", 1);
    
        var func:Function = null;
        var argum:*;
    
        function bb(f:Function=null, ...args):void
        {
            func = f;
            argum = args as Array;
            exec();
        }
    
        function exec():void
        {
            if (func == null) { return; }
            func.apply(this, argum);
        }
    

    This way, you can pass arguments as variables to a different function and execute them..

    Thanks to everyone taking the time to help...

提交回复
热议问题