如何在 ActionScript 中停止执行

发布于 2024-08-05 23:03:51 字数 112 浏览 2 评论 0原文

有什么方法可以停止 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

送你一个梦 2024-08-12 23:03:51

不,没有睡眠。对不起。

请参阅我的答案此处的选项: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.

扛刀软妹 2024-08-12 23:03:51

您需要考虑不睡觉。 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.

山人契 2024-08-12 23:03:51

没有办法像 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).

阿楠 2024-08-12 23:03:51

是的,有,但请注意 15 秒脚本超时。 (您可以在发布设置中更改 15 秒脚本超时...)

我过去发现,如果您正在寻找此功能,那么您就做错了:)

无论您想要完成什么,可能会调用事件侦听器。

//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...
}

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.

//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...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文