如何在 ActionScript 中停止执行
有什么方法可以停止 ActionScript 中的执行,例如 sleep() 方法吗?
我知道有一个 setTimeout() 方法,但是 setTimeout() 只是设置一个延迟执行的事件。
Is there any way to halt execution in ActionScript, such as a sleep() method?
I know that there is a setTimeout() method, but setTimeout() just sets up an event for deferred execution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,没有睡眠。对不起。
请参阅我的答案此处的选项:ActionScript:推动关闭到事件堆栈上?。它没有谈论睡眠,但我试图提供延迟函数调用的概述。
No. There is no sleep. Sorry.
See my answer here for options: ActionScript: pushing a closure onto the event stack?. It doesn't talk about sleeping, but I tried to provide an overview of deferred function calling.
您需要考虑不睡觉。 Actionscript 不是那种语言。由于 Flash 播放器在帧渲染和代码执行之间交替,因此在代码中休眠始终是一个坏主意,这就是为什么没有方法可以做到这一点。
话虽如此,您可以通过使用阻塞方法ExternalInterface.call并在Javascript中执行阻塞方法(如XHR请求)来实现这一点。
但这绝对是愚蠢的,所以不要这样做。
也许您需要的是一个
计时器
。You need to think in terms of not sleeping. Actionscript is not that kind of language. Because the flash player alternates between frame renders and code execution, sleeping in the code is always a bad idea, which is why there is no method to do it.
Having said that, you could achieve this by using the blocking method ExternalInterface.call, and in Javascript executing a blocking method (like XHR request).
Absolutely idiotic though, so don't do it.
Perhaps what you need is a
Timer
.没有办法像 PHP 那样暂停应用程序的所有执行,但有一些解决方法(除非您故意设置断点或创建运行时错误,但不要认为这就是您的意思)。可能这是因为通常 Flash 应用程序旨在在不到一“帧”的时间内执行所有脚本。
当用户松开网站焦点时,能够“暂停”网站的动画是很常见的。这可以通过侦听 Event.DEACTIVATE 来完成,然后删除 ENTER_FRAME 侦听器并终止所有正在进行的进程。
您还可以创建一个中央 EventDispatcher 来替换内部 ENTER_FRAME,这样您就可以无缝控制执行速度以及暂停/恢复(但不会停止执行脚本,也不会停止异步处理程序,例如加载程序等)。
There's no way to pause all execution of an application as in PHP, but there are workarounds (unless you set a breakpoint or create a runtime error on purpose, don't think that's what you meant). Probably this is because usually flash applications are meant to execute all the scripts in less than one "frame".
It's common to be able to "pause" the animations of a website when the user unfocus it. This can be made by listening to Event.DEACTIVATE and then remove the ENTER_FRAME listeners and kill all ongoing processes.
You could also create a central EventDispatcher to replace the internal ENTER_FRAME, this way you seamlessly control speed of execution as well as pausing / resuming (won't stop executing scripts, nor asynchronous handlers such as loaders etc. though).
是的,有,但请注意 15 秒脚本超时。 (您可以在发布设置中更改 15 秒脚本超时...)
我过去发现,如果您正在寻找此功能,那么您就做错了:)
无论您想要完成什么,可能会调用事件侦听器。
Yes, there is, though be aware of the 15 second script timeout. ( You can change that 15 second script timeout in the Publish Settings... )
I've found in the past that if you're looking for this functionality, you're doing something wrong :)
Whatever you're trying to accomplish is probably calling for an Event listener instead.