Flash Player 10.1 保持 8 FPS
2010-07-17 10:39
Flash Player 10.1 改善了浏览器中 SWF 内容的播放效能
在不可见的状态下,会自动调降播放速度至 2 FPS
或是当有声音播放时,则降为 8 FPS
影响的范围甚广,几乎所有时间性的函式都会被降速
像是 Timer, setInterval, enter frame event
甚至连下载进度的事件发生的时间也都被限制符合低 FPS 时间间隔
假如想要维持较高速度的执行频率
必须从 Javascript 定时透过 ExternalInterface 呼叫 SWF 内的 function
或是播放一个音乐~
为了维持 8 FPS 可以嵌入一个声音或是加载外部的声音档案
其实有一个很简单的方式就能达到相同的效果
建立一个空的 Sound 对象,呼叫 play 之后,马上 close 就行了
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.utils.getTimer;
import flash.utils.setInterval;
[SWF(width="300", height="200", frameRate="30")]
public class testFTP extends Sprite {
public var prevTime:Number = getTimer();
public function testFTP() {
this.graphics.beginFill(45652);
this.graphics.drawRect(0,0,300,500);
this.graphics.endFill();
var snd:Sound = new Sound(new URLRequest(""));
snd.play();
snd.close();
setInterval(function():void{
trace("here")
trace(getTimer() - prevTime);
prevTime = getTimer();
}, 50);
stage.addEventListener(Event.ACTIVATE, onEvent);
stage.addEventListener(Event.DEACTIVATE, onDEvent);
}
public function onEvent(e:Event):void {
trace("a>>>>>>>>>>>>>>>>")
trace(e.type);
}
public function onDEvent(e:Event):void {
trace("d<<<<<<<<<<<<<<<<<")
trace(e.type);
}
}
}