I'm using the Function.apply() method to send a dynamic number of arguments to
another function, and i'm running into much frustration.... it seems, whenever
I send an argument, it will trace the argument, but execute nothing else inside
the function, but... if the argument is Undefined, everything else runs fine...
I have no clue what is going on. can anybody help me with this?
My code is below:
/* ===== This is all inside of a class ===== */
var myDelay:Number = 1000; // Delay in ms
var myString:String = "test string"; // A Test Variable to Pass Around
// interval_int = setInterval
(this,FunctionToRun,delayAmt,intervalToClear,functionToRunAfterDelay,parameter1,
parameter2,...)
delay_int =
setInterval(this,"DelayRun",myDelay,"this.delay_int",myFunction,"test string")
private function DelayRun (delayInterval,functionName:Function) {
clearInterval(eval(delayInterval));
arguments.shift(); // Remove the DelayIntrval that was Cleared.
arguments.shift(); // Remove the FunctionName Argument
functionName.apply(null,arguments);
}
private function myFunction(testArg) {
trace("Test: " + testArg); // Traces Argument when its Sent
RunAnotherFunction(); // Only runs when testArg is NOT sent
}
EricNY523 - 30 Apr 2005 18:32 GMT
The problem was in this line:
functionName.apply(null,arguments);
It needed to be:
functionName.apply(this,arguments);
Now... would anybody be able to explain why this is? b/c I just tried it out
of dumb luck.