I'm loading a swf-file from my program written in as3 using the flash.display.Loader class. When I'm using the debug build configuration in FlashDevelop everything works fine. But when I'm using the release build configuration the program freezes for around two seconds efter the loader sends the progress events and before sending the complete event.
This is my program:
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");
}
}
}
In release I get the following output on the first frame:
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
After around two seconds where the program is frozen the line Completed on frame: 2
is added and the 'On frame X' counter starts ticking up. Debug build produces the same output but without the freeze.
Not all swf-files I have tried loading triggers the problem. The size of the file doesn't seem to affect anything. I have tried compiling and running on another computer with the same result.
What could cause this problem?
Edit: I noticed that if the program is compiled with debug=true the flash player takes around two seconds to start, the same length of time the flash player is frozen when debug=false.