动作脚本休眠功能 [英] Action Script Sleep function
问题描述
是否动作2.0 / 3.0有一些C#睡眠等效()?
Does actionscript 2.0/3.0 have an equivalent of c# sleep() ?
推荐答案
不是真的。你可以阻止(几乎所有)code执行的东西,如:
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());
但我不明白怎么会这样闪光灯有用。而且,在同一时间,像上面的code什么是一个非常糟糕的主意,因为玩家将冻结和停止响应(也可以给一个脚本超时如果超出超时限制,这是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).
如果您只是想拖延一张code的执行,你可以使用一个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屋!