在我的 flex 移动应用程序中,我有一个循环运行超过 100 次迭代。在每次迭代中,我都会更新特定标签的一些属性。由于循环很耗时,我需要在每次迭代时更新屏幕并显示中间结果。如何打破循环并刷新显示列表?
function theFunction():void{
for var i:int = 0; i < n; i++{
doBusyStuff();
label_1.text = "iteration"+" i";
}
}
最佳答案
在那种情况下,我更喜欢使用 flash.utils.setTimeout()
import flash.utils.setTimeout;
function theFunction(limit:int, current:int = 0):void
{
if (current >= limit)
return;
doBusyStuff();
label_1.text = "iteration "+ current.toString();
setTimeout(theFunction, 0, limit, current+1);
}
但是,setTimeout()
和 callLater()
都取决于滴答或帧速率,这意味着它们不会尽可能快地执行。因此,如果您还希望它运行得更快,您应该让它在每次调用时运行几个循环。
关于apache-flex - Flex如何使用callLater?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23341584/