How to stop execution in ActionScript

Is there a way to stop execution in ActionScript, such as the sleep () method?

I know that there is a setTimeout () method, but setTimeout () just sets an event for deferred execution.

+6
flex actionscript actionscript-3 flex3
source share
4 answers

Not. No sleep. I'm sorry.

See my answer here for options: ActionScript: pushing close on event stack? . He does not talk about sleep, but I tried to provide an overview of the call to deferred functions.

+3
source share

You need to think about not sleeping . ActionScript is not the right language. Since the flash player alternates between frames and code execution, sleeping in code is always a bad idea, so there is no way to do this.

Having said that, you can achieve this by using the ExternalInterface.call lock method and in Javascript that executes the lock method (e.g. XHR request).

Absolutely idiotic, so don't do this.

Maybe you need a Timer .

+1
source share

It is not possible to pause all application execution, as in PHP, but there are workarounds (if you do not set a breakpoint or create a runtime error, do not think what you meant). This is probably due to the fact that usually flash applications are designed to run all scenarios in less than one โ€œframeโ€.

Typically, you can โ€œpauseโ€ the animation of a website when the user focuses it. This can be done by listening to Event.DEACTIVATE, and then delete the ENTER_FRAME listeners and kill all current processes.

You can also create a central EventDispatcher to replace the internal ENTER_FRAME, so you can easily control the speed of execution, as well as pause / resume (do not stop scripts, as well as asynchronous handlers such as loaders, etc.).

0
source share

Yes, there is, although a script is aware of the 15 second timeout. (You can change this 15 second timeout script in publish settings ...)

In the past, I found that if you are looking for this functionality, you are doing something wrong :)

No matter what you try to execute, an event listener may be required instead.

 //adding this ENTER_FRAME event listener just to show that the script pauses for one // second before the first frame executes addEventListener( Event.ENTER_FRAME, onFrame ); function onFrame( event:Event ):void { trace( "first frame occurs after pause of", getTimer() + " ms" ); removeEventListener( Event.ENTER_FRAME, onFrame ); }; var startTime:int = getTimer(); var pauseTime:int = 1000; while( ( getTimer() - startTime ) < pauseTime ) { //do nothing... we're effectively pausing here... } 
-4
source share

All Articles