You don't need an array of urls, as you have no use for them,
you need an array of loader instances,
so that you have the correct order (as they are in the xml).

With e4x getting to the image urls is easy, and looping through them as well, so there really is no need to have them in a seperate array.

Something like this (from the top of my head):

private var data:XML = <data>
<img src="jpg/cinematic001.jpg" />
<img src="jpg/cinematic002.jpg" />
<img src="jpg/cinematic003.jpg" />
</data>;

private var imgLoaders:Array;
private var numLoaded:int = 0;
private var numTotal:int;

function loadImages():void {
   imgLoaders = new Array();
   var imgs:XMLList = data.img;
   var len:int = numTotal = imgs.length();
   var loader:Loader;
   for(var i:int=0; i<len; i++) {
       loader = new Loader();
       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, 
imgCompleteHandler);
       loader.load(new URLRequest(imgs[...@url));
       imgLoaders.push(loader);
}

function imgCompleteHandler(event:Event):void {
   numLoaded += 1;
   event.currentTarget.removeEventListener(Event.COMPLETE, imgCompleteHandler);
   if(numLoaded == numTotal) {
       // all images are loaded
   }
}

With the above it doesn't matter in what order the images finish loading, you have the correct order in the array (imgLoaders) and you know when all images are loaded when numLoaded equals numTotal.

regards,
Muzak

----- Original Message ----- From: "Paul Andrews" <p...@ipauland.com>
To: "Flash Coders List" <flashcoders@chattyfig.figleaf.com>
Sent: Saturday, July 25, 2009 9:42 PM
Subject: Re: [Flashcoders] Image loader problem


Cor wrote:
Joseph,

I always like to write all the code myself. :-)
But I will look at this to learn from at least and maybe using someone else
his classes.

Thank you very much!!

Cor

-----Original Message-----
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Joseph
Masoud
Sent: zaterdag 25 juli 2009 15:04
To: Flash Coders List
Subject: Re: [Flashcoders] Image loader problem

Have you considered using existing bulk loaders?
http://code.google.com/p/bulk-loader/

You've got a relatively complex task ahead if you're going to write  the code 
all by yourself.

Essentially the idea is to have two stacks, a loading stack and a pending stack [list of assets to be loaded]. Ensure there is only one loader in the loading stack at any time during the loading process if order is important.

I suggest creating a separate data type for storing information about the images, however I think you might want to consider letting one object deal with the loading process.

Many thanks,
Joseph

On 25 Jul 2009, at 13:53, Cor wrote:


To solve your issue you might write the code so that the next image in
the sequence doesn't load
or start to load until the previous is complete.

Yes, but I dont know how.

You could bulk load the images and stuff them in an array then use a  loop to
run through
the array to get the image and it's properties so that you can align
everything the way you want.

Frankly I just want them in the same order as they are in my xml.


Here's a nudge in the right direction. Store the image paths in an array - imagePaths and the loaded images in loadedImages. Use i as a counter through the array. I have ommited variable declarations. This is just a bare bones, with bits missing! Adapt to your case.

Paul

function loadImage():void
{
if ((i<imagePaths .length) && (i>= 0))
{
loader =new flash.display.Loader();
urlreq = new URLRequest(imagePaths [i]);

loader .contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader .contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onIOError);
loader .load(urlreq);
}
}

public function _onLoadComplete(e:Event):void {
loadedImages[i]= e.currentTarget.content;
i++;
if (i<imagePaths .length)
{
loadImage();
}
else
{
useImages();
}
}


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to