简体   繁体   English

setInterval在独立Flash Player中非常慢

[英]setInterval very slow in standalone flash player

setInterval function in Flash works fine with builtin flash player (testing phase) but when I use same (published) swf on standalone player it is almost 10 times slower than that. Flash中的setInterval函数在内置Flash Player(测试阶段)中可以正常工作,但是当我在独立播放器上使用相同的(已发布的)SWF时,它的速度几乎慢了十倍。 To confirm i created a simple counter without any graphics and noticed this issue. 确认我创建了一个没有任何图形的简单计数器,并注意到了这个问题。

PS: I have checked on various player versions and even on internet browsers and even on VMWare on windows 7. I tried all other options like cpu and gpu acceleration but no improvement. PS:我检查了各种播放器版本,甚至在Internet浏览器上,甚至在Windows 7上的VMWare上,我都尝试了所有其他选项,如cpu和gpu加速,但没有任何改善。

My testbench:only one frame and one dynamic text field with name "te". 我的测试台:只有一帧和一个动态文本字段,名称为“ te”。 following is the action script 以下是动作脚本

var lo=0;
function f():void{
    te.text=lo++;
}
setInterval(f,0);

The true answer here is that you are using setInterval with a value of 0 . 真正的答案是,您正在使用值为0 setInterval Which means that you want to do as many possible calls to the function f in a frame as possible. 这意味着您希望在一个框架中尽可能多地调用函数f But because of the nature of AS3, the frame switching is delayed so that the code inside can be executed (frame rate drop). 但是由于AS3的特性,帧切换被延迟了,因此内部的代码可以执行(帧速率下降)。 But you never finish executing - your setInterval keeps going forever and is busting up everything. 但是您永远不会完成执行setInterval会一直持续下去,并且会破坏一切。 It's like writing while (true) loop.. 这就像在编写while (true)循环时一样。

So just start using it properly and you won't have any problems. 因此,只要正确开始使用它,您就不会有任何问题。

I recommend you to use flash Timer class to precise interval time, it works more efficent compared to ENTER_FRAME or setInterval 我建议您使用Flash Timer类来精确间隔时间,与ENTER_FRAME或setInterval相比,它的工作效率更高

var myTimer:Timer = new Timer(1); //ms
var time = 0;
myTimer.start()
myTimer.addEventListener(TimerEvent.TIMER,timerHandle);

function timerHandle(e:TimerEvent){
    txt_time.text = time.toString();
    time++;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM