all groups > flash actionscript > september 2005 >
You're in the

flash actionscript

group:

Pause Loop



Pause Loop gijbelsy
9/21/2005 10:15:55 PM
flash actionscript: how can I pause a FOR loop for X secs/msecs before continueing with the next run ?

Something like this



for(i=0;i<5;i++){
//DO SOME CODE
PAUSE(500);
Re: Pause Loop Jeckyl
9/22/2005 12:00:00 AM
You can't ... that makes no sense in a flash environment.

Instead either:
* split your processing over frames (have a set of frames that loop)
* use an onEnterFrame
* use a setInterval
--
Jeckyl

Re: Pause Loop nITiNkIlLeRmEeRuT
9/22/2005 9:36:06 AM
Ok i just give it a go.

logic which i thought

loop starts
met a condition > pause start (no increment in loop)
time reached and start again

Can anyone help what i am doing wrong

var intervalID:Number;
// to store interval id
var flag:Boolean = false;
// track execution of for loop
var pauseInterval:Number = 5;
//time to pause loop
var counter:Number = 0;
//increment counter for time check
var bool:Boolean = false;
// to ensure fPause function execute only once.
var i:Number = 1;
//loop variable
while (i <= 20) {
if (i == 10) {
//after 10 loop should be paused
if (!bool) {
fPause(pauseInterval);
//call function to pause
bool = true;
// should not execute again
}
}
if (!flag) {
// normal tracing if pause not encountered
trace(i);
i++;
}
}
//pause function
function fPause(interval) {
flag = true;
intervalID = setInterval(track, 1000);
}
//check pause interval is reached
function track() {
counter++;
if (counter == pauseInterval) {
// condition met now start the loop
flag = false;
i++;
clearInterval(intervalID);
}
}
AddThis Social Bookmark Button