Is there any way to implement waiting for, say, 3 seconds in ActionScript, but to stay within same function? I have looked setInterval, setTimeOut and similar functions, but what I really need is this:
public function foo(param1, param2, param3) {
//do something here
//wait for 3 seconds
//3 seconds have passed, now do something more
}
In case you wonder why I need this – it is a legal requirement, and no, I can’t change it.
Use the
Timerto call a function after 3 seconds.To do this properly, you should create the timer as an instance variable so you can remove the listener and the timer instance when the function is called, to avoid leaks.
You could also use another function inside your
foofunction and retain scope, so you don’t need to pass variables around.