动作脚本睡眠功能 [英] Action Script Sleep function
问题描述
actionscript 2.0/3.0 是否有等效的 c# sleep() ?
Does actionscript 2.0/3.0 have an equivalent of c# sleep() ?
推荐答案
并非如此.您可以使用以下内容阻止(几乎所有)代码执行:
Not really. You could block (almost all) code execution with something like:
function sleep(ms:int):void {
var init:int = getTimer();
while(true) {
if(getTimer() - init >= ms) {
break;
}
}
}
trace("hello");
trace(getTimer());
sleep(5000);
trace("bye");
trace(getTimer());
但我不明白这在 Flash 中如何有用.而且,同时,像上面的代码这样的任何东西都是一个非常糟糕的主意,因为玩家会冻结并变得无响应(如果超过超时限制,默认情况下为 15,也可能会导致脚本超时).
But I don't see how could this be useful in flash. And, at the same time, anything like the above code is a very bad idea as the player will freeze and become unresponsive (and could also give a script timeout if you exceed the timeout limit, which is 15 by default).
如果你只是想延迟一段代码的执行,你可以使用 Timer 对象或 setTimeout 函数.但是,这将是非阻塞的,因此您必须使用像 TandemAdam 建议的某种标志.充其量它会变脆.
If you merely want to delay the execution of a piece of code, you can use a Timer object or the setTimeout function. This will be non-blocking, though, so you'll have to use some kind of flag like TandemAdam suggested. It'll be brittle, at best.
也许有更好的方法可以解决您的问题,但不清楚您想在问题中完成什么.
Maybe there's a better approach for your problem, but it's not clear what are you trying to accomplish in your question.
这篇关于动作脚本睡眠功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!