Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Sleep / Wait / Pause functions in AS2.0?

Participant ,
Jul 06, 2008 Jul 06, 2008
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.
TOPICS
ActionScript
3.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2008 Jul 06, 2008
hi
you need use from inerval and call function whit (setInterval)
and when you want to stop function use (clearInerval)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 06, 2008 Jul 06, 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! 🙂
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2008 Jul 06, 2008
LATEST
there is no sleep/pause/wait function in as2 (or as3).
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines