How many times have you been coding Actionscript and needed to run some code in a second, or two, or whatever? I know, you can create a setInterval, blah, blah, blah. But that’s such a pain in the the ass.
So, I made a class with just one method to do make it easier for you to wait a second. If you need to call a function/method in, say half-a-second, then all you would write is this:
Wait.For(500, myMethod).
Done.
But, wait, there’s more. You can pass arguments that you need to send to your function/method. Just like this:
Wait.For(500, myMethod, “coffee”, “hot”, “cream”, suger”);
is that sweet or what?
There is a limit of 10 arguments that you can pass. If you really need to send more then edit the class yourself.
Here’s the code for the class below or you can download the file: Wait.as – Wait.zip.




There is an undocumented function in Flash that does that: setTimeout. It works very similar to setInterval.
You can find out how to use it at http://www.flashguru.co.uk/flash-8-settimeout/
By the way, you should use dynamic arguments. The way you send arguments to the callback function is not very elegant, and it limits the amount of arguments to send. Take a look to this:
http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary369.html
Cheers
Or you could use:
callback(a.slice(2, a.length));
to pass as many arguments as needed
@Rasmus, true enough. Good thanking.
Flash already has this:
setTimeout(scope, “function”, milliseconds, param1, param2, etc);
@Andy, you sure that isn’t a custom class you wrote? setTimeout isn’t in the help files and the following code doesn’t do anything:
setTimeout(this, CB, 100, “hi”);
function CB(arg:String):Void {
trace(arg);
}
setTimeout is an undocumented function introduced in Flash 8. For more info see this post from Flashguru: http://www.flashguru.co.uk/flash-8-settimeout/
@Rasmus, wonderful, thanks for pointing this out. The problem with the code above is that here is no ‘scope’ parameter. So this works as expected.
setTimeout(CB, 1000, “hi”);
function CB(s:String):Void {
trace(s);
}
did you try _global.setTimeout(CB, 1000, “hi”); ?
i use that when i need a method call to wait
:)
sorry i forgot the scope:
(inside a class)
timerInterval = _global.setTimeout(this, “functionName”, 100);
@wolfito, you know, I’ve never really used _global before. I think static classes do the same thing for me.
By the way, wicked cool sight you have. I can’t read it but I love the detail you put into it. Something as simple as making the text coast to a stop when scrolling is a very sweet effect and looks quite professional. Kudos.