我正在使用flash.display.Loader類從我的程序中加載一個swf文件。當我在FlashDevelop中使用調試版本配置時,一切正常。但是,當我使用發佈版本配置時,在加載器發送進度事件之後以及發送完整事件之前,程序凍結約兩秒鐘。flash.display.Loader塊在發佈版本中加載
這是我的計劃:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.ApplicationDomain;
import flash.text.TextField;
public class Main extends Sprite {
private var frameCounter:int;
private var frameCounterField:TextField = new TextField;
private var statusField:TextField = new TextField;
function Main():void {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
addEventListener(Event.ENTER_FRAME, frame);
frameCounterField.text = "On frame " + frameCounter.toString();
addChild(frameCounterField);
statusField.y = 40;
statusField.width = 300;
addChild(statusField);
var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
var urlReq:URLRequest = new URLRequest("SomeFile.swf");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(urlReq, context);
}
private function frame(event:Event):void {
frameCounterField.text = "On frame " + (++frameCounter).toString();
}
private function onProgress(event:ProgressEvent):void {
statusField.appendText("Progress on frame: " + frameCounter.toString() +
" Loaded: " + event.bytesLoaded + "/" + event.bytesTotal + "\n");
}
private function onComplete(event:Event):void {
statusField.appendText("Completed on frame: " + frameCounter.toString() + "\n");
}
}
}
在釋放我得到的第一幀以下的輸出:
On frame 1
Progress on frame: 1 Loaded: 0/182468
Progress on frame: 1 Loaded: 65536/182468
Progress on frame: 1 Loaded: 131072/182468
Progress on frame: 1 Loaded: 182468/182468
大約兩秒鐘後,程序被凍結,添加了行Completed on frame: 2
,'On frame X'計數器開始計時。調試版本產生相同的輸出,但沒有凍結。
並非所有我試過加載的swf文件都觸發了這個問題。文件的大小似乎不影響任何內容。我已經嘗試編譯並在另一臺計算機上運行,結果相同。
什麼可能導致此問題?
編輯:我注意到,如果程序編譯時debug = true,flash播放器需要大約兩秒的時間才能啓動,當debug = false時Flash播放器被凍結的時間相同。