PDA

View Full Version : preload multiple



vxd
July 13th, 2009, 09:48 AM
Hi all,
I've been searching for hours now but I haven't found anything.

What I'm trying to do is get the total bytes of all the files I want to load and display the percentage loaded of total bytes and bytes loaded of all the files.

Its a slideshow so i want all the files loaded and then it will play.
I've looked at bulk-loader but it wasn't what I needed.

The image are loaded from an xml file. I think I would need to create an Array and then find out the total bytes but I don't know how to reference the loader in the progress.

here is the code:


private function loadImages():void {


//Loop through the images in the xml file and then load them
for (var i:int = 0; i < totalItems; i++) {

//Create a new loader to every image.
imageLoader = new Loader();
//Load the images
imageLoader.load(new URLRequest(xmlList[i].@src));

//Call fucntion imageLoading when images are being loaded
imageLoader.contentLoaderInfo.addEventListener(Pro gressEvent.PROGRESS, imageLoading);
// Call function imageLoaded when the images are loaded
imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, imageLoaded);

}//loop

}//loadImages

private function imageLoading(evt:ProgressEvent):void {

// work out whay has been loaded
totalLoaded = Math.round((evt.bytesLoaded / evt.bytesTotal) * 100);
//add results of totalLoaded in to tPercent
tPercent.text = totalLoaded + "%"+" " + Math.round((evt.bytesTotal))/1000;
//x and y of tPercent
tPercent.x = stage.stageWidth / 2 - tPercent.width/2;
tPercent.y= 350;//stage.stageHeight / 2 - tPercent.height/2;
//set text format
tPercent.setTextFormat(tfPercent);
//add tPercent to stage
addChild(tPercent);

}

If someone could just tell me the how it would work i should be able to figure it out.

thanks
vxd

453.0
July 13th, 2009, 10:14 AM
I think you are not walking the right path with that attempt. Instead, I'd look at the problem like this:

Let's say you have 2 files to load total. Obviously, you know how many files you are going to load. So, 2 = 100%. You should start loading 1 file at a time and also keep in mind that total files are = 100%. So, if you load only 1 file, that's half the files loaded, so you'll have 50% loaded out of total. Once the last file is loaded, you'll have 100%. I'm not really sure how to explain in, it's because of my not so great English but I hope you get the idea.

If you had 4 files, then each file would represent 25% of the total number. By knowing how much a file represents out of the total number, you can easily calculate the amount current loaded without having to create a loop and instantiate 100000 Loader objects for 100000 files. Take it easy, load a file at a time and instead, use some simple math to display the percentage currently loaded from the total ( as in my example... knowing 1 file is loaded out of 4, you have 25% loaded, next file will add up to 50%, the third to 75% and finally 100% ... you just need some simple math to get this up and running... and not only up and running, but up and running in an efficient and professional way ).

EDIT: Obviously, when you are loading your first file, you'll be going up to 25% max and not 100% for each file as you'd normally go. It's really not hard to achieve, it just needs a bit of planning and some simple math.