Skip to main content
Inspiring
July 6, 2008
Question

Sleep / Wait / Pause functions in AS2.0?

  • July 6, 2008
  • 2 replies
  • 3176 views
Hi.
I wanted to ask, if there is any easy way to make my code stop executing until I set up a flag.
A basic example of what I want to is:

// .... code 1 ....
flag=1;
while(flag == 1) {
Sleep(500);
}
// .... code 2 ....

The "code 2" need to start executing if "flag" is set to 0 with some interval, or listener.
Still, if I use just:
while (flag==1);
I will consume all CPU power without any reason.

Is there any Flash function that will prevent code execution of current script from a predefined time (i.e. 500msec) without consuming CPU usage?

If not, is there any other way?
I could use setInterval() but then the "code 2" should be written in the Interval function, and I don't want that because it will mess up all my codes!

Thanks.
This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
July 6, 2008
there is no sleep/pause/wait function in as2 (or as3).
Participant
July 6, 2008
hi
you need use from inerval and call function whit (setInterval)
and when you want to stop function use (clearInerval)
Inspiring
July 6, 2008
Hi m8.
Yea, I know that - this is the way I am creating my project.
But with the interval function you have to break your code to 2 functions: One of your main function, one on the interval function (to be executed after the flag change). And this mess up the code, specially if we talk about 500-1000 lines of code in an object which need to check with 3-5 flags with logical combination with those flags... too messy.....! :P

Still intervals seems to be the only way. :)

Still hoping someone to find another!!!... AS2.0 should have a "sleep" or "pause" or "wait" function that will make the object's called code to stop executing for some milliseconds. This would come very handy! :)