PDA

View Full Version : Pause inside actionscript! Help!!


parakalus
06-15-2005, 10:50 AM
am trying to get the code to pause until a bool value is set to true, at which time the function will carry on and return a different value. So far it does do the waiting loop, but it ALSO skips over it and returns the other value as well!! Any help would be greatly appreciated!! heres the code from the end of the function:



var waitID = setInterval(function () {
trace("waiting... "+answered);
if (answered == true) {
trace("answered!!");
clearInterval(waitID);
play(); // action to continue
}
}, 1000);

return(c_or_w);

}

jsebrech
06-15-2005, 11:54 AM
setInterval doesn't make code wait. The code keeps executing, but, after the interval is up, the code you told setInterval to execute is executed as well.

In short, if you can't continue until setInterval executes, you shouldn't execute any code after the setInterval.

parakalus
06-15-2005, 12:42 PM
is there anyway of making actionscript wait for a response from a movieclip? tried using while loops, but flash just ends up in infinite loops, no matter how/where you put the exiting condition.

jsebrech
06-15-2005, 02:14 PM
Yes, but, it's tricky. Stop thinking in terms of code flow, and start thinking in terms of events. Actionscript is not multi-threaded, so loops that keep checking if something has changed generally don't make sense. What you do is you handle an event (onenterframe, or the one caused by setinterval), and in that handler you check if you can continue code execution, and if so, call another function to execute the rest of what you need to do.