Actionscript 3.0 Problem: Loader doesn't fire COMPLETE event.

This seems to appear only in Internet Explorer. When using the Loader to load an external image into Flash the COMPLETE event are sometimes not fired, while the PROGRESS event is fired frequently and the bytesLoaded increses until the whole file has been downloaded. Other events doesn't fire either, like INIT.

There is a workaround for Actionscript 2.0 (AS2) which can be found here: http://jeff.mxdj.com/loader_component_and_internet_explorer.htm, but it doesn't work on Actionscript 3.0 (AS3).

However it seems that a second call to load() will produce the correct event calls a second time.

Here's the base code which uses the Loader object:

var ldr:Loader = new Loader(); 
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
var imgHolder:MovieClip=MovieClip(getChildByName("imgHolder"));
imgHolder.addChild(ldr);
var urlReq:URLRequest = new URLRequest("http://url/myimage.jpg");
ldr.load(urlReq);

And here's the fix:

var reLoaded:Boolean=false; 
function progressHandler(e:ProgressEvent) {
if(e.bytesLoaded>0&&!reLoaded) {
reLoaded=true;
ldr.load(urlReq);
}
}

What it does is it waits for the first couples of bytes to be read and then fires the load() function again, thus canceling the first load()-call. The events should be called as expected this time, even in Internet Explorer!

Related posts:

Comments

comments powered by Disqus