Using function.apply and a dynamic parameter array with setTimeout

Hi everyone,

I’m racking my brains to find a solution to this problem. I’ve got so far, but have no idea how (or if) this can be solved.

I’m trying to make a function scheduler in flash using the setTimeout object. It works by sending an array of objects containing properties like ‘waitBefore’, ‘waitAfter’ and the function to call, like this:[INDENT]{waitBefore:1.5, action:fSayHello, waitAfter:2}
{waitBefore:0.5, action:fSayGoodbye, waitAfter:0}
[/INDENT]Then when this array is passed to the scheduler it will call fSayHello after 1.5 seconds, then fSayGoodbye after 2.5. This works fine.

Then I tried to add a parameter property to the function like:[INDENT]{waitBefore:1.5, action:fSay, param:“Hello”, waitAfter:2}[/INDENT]The parameter is passed no problems - but some of the functions I’m calling need more than one parameter. So I tried sending an array to the scheduler function, and this only passed the array on to the scheduled function rather than splitting it up - of course.

After some research I found the function.apply method. So I tried using that with the setTimeout object, with no luck.
If I say setTimeout(fSay.apply(aParameters), nDelay); then it ignores the delay and just runs the function with the passed parameters instantaneously. I can understand why, as you can only pass a function reference to the setTimeout object. Can anybody think how to get around this?

I hope someone can point me in the right direction, and I hope this explanation makes sense!

Thank you all,

Tim