# Preload multiple jpgs individually

**URL:** <https://forum.kirupa.com/t/preload-multiple-jpgs-individually/177144>\
**Category:** flash\
**Created:** [January 30, 2006, 5:05pm UTC](https://forum.kirupa.com/t/preload-multiple-jpgs-individually/177144 "2006-01-30T17:05:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bocafloja](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bocafloja](https://forum.kirupa.com/u/bocafloja)\
**Post date:** [January 30, 2006, 5:05pm UTC](https://forum.kirupa.com/t/preload-multiple-jpgs-individually/177144/1 "2006-01-30T17:05:39Z")

</div>

Hello, I’m building gallery which loads dynamic jpgs from an xml into a movieclip which is scrolled. By now the script works fine but I want to add a preload bar to each of the jpgs while loading, and here is where I don’t know what’s wrong with the code.  
Here it is:

[AS]  
separation = 2;  
archive = new XML();  
archive.ignoreWhite = 1;  
parse = function (success) {  
if (success) {  
\_root.createEmptyMovieClip(“gallerymenu”, 20);  
\_root.gallerymenu.\_x = 50;  
\_root.gallerymenu.\_y = 70;  
\_root.gallerymenu.\_visible = 0;  
for (i=0; i\<this.firstChild.childNodes.length; i++) {  
var button = \_root.gallerymenu.attachMovie(“btgallery”, “button”+i, i);  
button.textobt.text = this.firstChild.childNodes\*.attributes.name;  
button.\_x = i\*(\_root.gallerymenu[“button”+i].\_width+separation);  
button.targetgal = this.firstChild.childNodes\*.childNodes.length;  
button.targetimages = this.firstChild.childNodes\*;  
button.onRelease = function() {  
clipArray = new Array();  
sizeArray = new Array();  
// create arrays from the xml nodes  
for (var j = 0; j\<this.targetgal; j++) {  
clipArray.push(this.targetimages.childNodes[j].attributes.urls);  
sizeArray.push(this.targetimages.childNodes[j].attributes.image\_w);  
}  
//trace(clipArray);  
//trace(sizeArray);  
var imagewidth:Number= 0;  
for (var k = 0; k\<clipArray.length; ++k) {  
// // loops through array and dynamically creates containers for each url and attaches preloader instances  
var clip:MovieClip = \_root.holder.createEmptyMovieClip(“clip”+k, k);  
\_root.holder.holderload.attachMovie(“preloader”, “preloader”+k, k);  
\_root.holder.holderload[“preloader”+k].\_x = imagewidth;  
targetpreloader = \_root.holder.holderload[“preloader”+k];  
// //preloading function  
my\_mc = new MovieClipLoader();  
preload = new Object();  
my\_mc.addListener(preload);  
preload.onLoadStart = function(targetMC) {  
trace(“started loading “+targetMC);  
};  
preload.onLoadProgress = function(targetMC, lBytes, tBytes) {  
targetpreloader.bar.\_width = (lBytes/tBytes)\*100;  
targetpreloader.pText.text = “Loading image”+Math.round((lBytes/tBytes)\*100)+”%”;  
};  
preload.onLoadComplete = function(targetMC) {  
[//targetpreloader.removeMovieClip](https://targetpreloader.removeMovieClip) ();  
trace(targetMC+" finished");  
};  
// //end of preloading function  
my\_mc.loadClip(clipArray[k], clip);  
// spacing  
clip.\_y = 25;  
clip.\_x = imagewidth;  
var incremento:Number = Number(sizeArray[k]);  
var imagewidth:Number = imagewidth + (incremento +10);  
//trace (imagewidth);  
//  
}  
}  
button.onRollOver = function() {  
this.bullet.gotoAndPlay(2);  
};  
button.onRollOut = function() {  
this.bullet.gotoAndPlay(1);  
};  
}  
\_root.gallerymenu.\_visible = 1;  
}  
};  
archive.onLoad = parse;  
archive.load(“galleries.xml”);  
stop();  
[/AS]

Also I want to know if the jpgs can be loaded sequentially, I know I have to use the onLoadInit but don’t really know how.  
Any help will be very appreciated.  
Thank you.

By the way the xml I’m using to load the pictures is this:

```auto

<photo1>
	<gallery name="fashion1">
		<image urls="fashion1/01.jpg" image_w= "519"/>
		<image urls="fashion1/02.jpg" image_w= "501"/>
		<image urls="fashion1/03.jpg" image_w= "596"/>
		<image urls="fashion1/04.jpg" image_w= "500"/>
	</gallery>
	<gallery name="fashion2">
		<image urls="fashion2/01.jpg" image_w= "312"/>
		<image urls="fashion2/02.jpg" image_w= "322"/>
		<image urls="fashion2/03.jpg" image_w= "336"/>
		<image urls="fashion2/04.jpg" image_w= "320"/>
	</gallery>
	<gallery name="travel">
		<image urls="travel/01.jpg" image_w= "320"/>
		<image urls="travel/02.jpg" image_w= "366"/>
		<image urls="travel/03.jpg" image_w= "325"/>
		<image urls="travel/04.jpg" image_w= "400"/>
	</gallery>
</photo1>

```

here you can download the .fla and the other files If you wnat to see how it works. It’s only 520 kb  
[http://www.shaktiprod.com/scrollgallery.zip](http://www.shaktiprod.com/scrollgallery.zip)  
Also you can see the gallery here:  
[http://www.shaktiprod.com/photo1/phototest5(mc).html](http://www.shaktiprod.com/photo1/phototest5(mc).html)
