我正在使用 flash.display.Loader 类从我用 as3 编写的程序中加载一个 swf 文件。当我在 FlashDevelop 中使用调试构建配置时,一切正常。但是当我使用发布构建配置时,程序在加载程序发送进度事件之后和发送完整事件之前冻结大约两秒钟。
这是我的程序:
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添加了行,并且“在 X 帧上”计数器开始计时。调试构建产生相同的输出但没有冻结。
并非我尝试加载的所有 swf 文件都会触发问题。文件的大小似乎没有任何影响。我尝试在另一台计算机上编译和运行,结果相同。
什么可能导致这个问题?
编辑:我注意到如果程序使用 debug=true 编译,flash 播放器大约需要两秒钟才能启动,当 debug=false 时,flash 播放器冻结的时间长度相同。