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); } :)
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++; }
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++; }
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++; }
Don't see what you're looking for? Try a search.
|