PDA

View Full Version : Pausing execution of code in a for loop between each loop. Howto?



ChillDown
January 20th, 2008, 11:53 PM
I have a for loop which runs x amount of times and between each loop i'd like to implement a small pause of execution of the code. How would i do that? Can something like that only be done using a timer? If so how would i go about doing that and what things should i import? (Trying to do this in a class)
Though i'm wondering if there's an easier way than timers to be able to do something like that, like C's sleep() function for example.

Dazzer
January 21st, 2008, 01:22 AM
Don't forget that Flash is a Frame based platform... so there is no such thing as Sleep. It enters a new frame all the time.

Hence, you have to settle for the Timer class. It really isn't that difficult. The only thing is that instead of a for loop you will be using a Timer only (implementing a pause in the for loop would mean that flash cannot execute any other code until the forloop is complete)

The timer class is

flash.utils.Timer;

Read documentation for usage.

springframework
January 21st, 2008, 06:00 AM
actionscript isn't multithreaded, so if a sleep call existed it would just pause the whole program from doing anything. don't try to replicate a sleep call with a while loop.


*̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡ ̴̡ı̴̴̡
actionscript 3.0 vancouver jesse couch (http://www.jessecouch.com)