all groups > flash actionscript > november 2004 >
You're in the

flash actionscript

group:

How to control time intervals btwn loops??????


How to control time intervals btwn loops?????? zzdobrusky
11/28/2004 6:58:48 PM
flash actionscript: Hi, This is supposed to be my final project at school but I am realy stuck!
Anybody help? I would like to have a loop where time intervals btwn loops are
different (random), is there any way to accomplish this in action script? I've
already spent hours figuring out how to do that, but nothing works, I don't get
it why this doesn't work???? It just gives endless loop??!!! i = 1;
while(i<=10) { // calculates random time hitTime =
Math.ceil(Math.random()*5)*1000; trace('hitTime =' + hitTime);
// calls function that should stop a loop for a hitTime wait(hitTime);
// something here to do i++; } function wait(interval) {
trace('inside wait i=' + i); idInt = setInterval(clearInt, interval); }
function clearInt() { trace('inside clearInt i=' + i); clearInterval(idInt);
} :)
Re: How to control time intervals btwn loops?????? NSurveyor
11/28/2004 7:13:46 PM
i = 1;
while(i<=10) {
// calculates random time
hitTime = Math.ceil(Math.random()*5)*1000;
trace("hitTime =" + hitTime);
// calls a for loop that stops a loop for a hitTime
for(start = new Date();end-start<hitTime;end = new Date())
}
// something here to do
i++;
}

Re: How to control time intervals btwn loops?????? NSurveyor
11/28/2004 7:14:21 PM
My bad, I made a mistake. Use this:

i = 1;
while(i<=10) {
// calculates random time
hitTime = Math.ceil(Math.random()*5)*1000;
trace("hitTime =" + hitTime);
// calls a for loop that stops a loop for a hitTime
for(start = new Date();end-start<hitTime;end = new Date()){
}
// something here to do
i++;
}
Re: How to control time intervals btwn loops?????? zzdobrusky
11/28/2004 11:13:57 PM
thanks for reply, I may not understand it, I tried this but still it doesn't
seem to go through that for-loop, while-loop is executed without any notice to
for-loop, it can be some flaw in actionscript though: i = 1; while(i<=10) {
// calculates random time hitTime = Math.ceil(Math.random()*5)*1000;
trace('hitTime =' + hitTime); // calls a for loop that stops a loop for a
hitTime for(startT = new Date();endT-startT<hitTime;endT = new Date()){
trace('startT = ' + startT + ' endT = ' + endT); } // something here
to do trace('i = ' + i); i++; }
AddThis Social Bookmark Button