I am using this class to load multiple images synchronously. Somehow the loader doesn't trigger any event (Event.COMPLETE, ProgressEvent.PROGRESS), strangely I also don't get any errors (using FlashDevelop and Flex3 SDK).
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLRequest;
public class MultiImgLoader extends EventDispatcher
{
private var img_array:Array;
public var images:Array;
private var loader:Loader = new Loader();
public function MultiImgLoader(img_array:Array)
{
this.img_array = img_array;
trace("[MultiImgLoader] about to load " + img_array.length);
if (img_array.length > 0)
{
load(img_array[0]);
}
}
private function load(img:String):void
{
trace("[MultiImgLoader] load " + img);
loader.addEventListener(ProgressEvent.PROGRESS, progress);
loader.addEventListener(Event.COMPLETE, this.ready);
var req:URLRequest = new URLRequest(img);
loader.load(req);
}
public function ready(ev:Event):void
{
var key:String = ev.target.contentLoaderInfo.url;
trace("[MultiImgLoader] ready " + key);
images.push( { key : ev.target } );
if (img_array.length > images.length)
{
for (var i:int = 0; i < img_array.length; i++ )
{
if (img_array[i] == key)
{
load(img_array[i+1]);
}
}
}
}
public function progress(ev:ProgressEvent):void
{
trace(ev.bytesLoaded);
}
}
}