PDA

View Full Version : Delaying a code statement


ErikL
01-21-2003, 12:14 PM
I am working on a machine emulator in Flash for training. The button panel is all decked out in flash, and through ActionScripting, the buttons all work as they are set to on the shovels....exept.
Clicking a button causes the indicator light to light to quickly. On a shovel weighting thousands of tons, this process takes time. On the flash presentation it is instantaneous.

Is there any easy way to delay a statement...for example:

BTNRUN.onRelease = function(){
//Turn on the RUN indicator lamp
//.....Wait 3 seconds?
mvcRun.nextFrame();
RunOn = true;

Thanks,

pom
01-21-2003, 03:33 PM
Use setInterval. There are lots of examples on the forum.

pom :)

d2mstrbldr
01-23-2003, 12:42 AM
Here is a prototype I wrote a while back(http://proto.layer51.com/d.aspx?f=454) that acts like a javascript setTimeout() function.

CODE:

movieclip.prototype.pause = function(dur, func, params) {
pauseID = setInterval( unPause, dur, func, params);
}

movieclip.prototype.unPause = function(func, params) {
clearInterval(pauseID);
eval(func).apply(null, params);

}

USAGE:

//BEGIN CODE
myFunction = function(arg1,arg2) {
trace(arg1);
trace(arg2);
};
//END CODE

Then just call the pause passing the function name as a
string, and the parameters for the function in an array:

//BEGIN CODE
pause(1000,"myFunction",["param1","param2"]);
//END CODE


So on your example ErikL after inlcuding the top two prototypes you could do the following:


myFunction = function() {
mvcRun.nextFrame();
RunOn = true;
}



BTNRUN.onRelease = function(){
//Turn on the RUN indicator lamp
//.....Wait 3 seconds?

pause(3000,"myFunction");
}