# Trying to preload a doc with multiple jpgs

**URL:** <https://forum.kirupa.com/t/trying-to-preload-a-doc-with-multiple-jpgs/252951>\
**Category:** flash\
**Created:** [February 25, 2008, 8:20pm UTC](https://forum.kirupa.com/t/trying-to-preload-a-doc-with-multiple-jpgs/252951 "2008-02-25T20:20:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ethereal](https://avatars.discourse-cdn.com/v4/letter/e/59ef9b/32.png) [@Ethereal](https://forum.kirupa.com/u/Ethereal)\
**Post date:** [February 25, 2008, 8:20pm UTC](https://forum.kirupa.com/t/trying-to-preload-a-doc-with-multiple-jpgs/252951/1 "2008-02-25T20:20:36Z")

</div>

Hi everyone. I’m trying to create a flash document that just does a slideshow through the images, but the image paths are all in an external xml file (this is because we are going to randomize that xml file on the fly with server scripting) and I want a preloader that loads the swf and all 5 of the external images that are in the document. The way I was able to get it to work is to use this script to load the XML doc and the images:

function loadXML(loaded) {

if (loaded) {

//pulls all data from the xml file  
xmlNode = this.firstChild;  
path = [];  
total = xmlNode.childNodes.length;  
for (i=0; i\<total; i++) {

path\* = xmlNode.childNodes\*.childNodes[0].firstChild.nodeValue;

}  
changeImage();

} else {

content = “file not loaded!”;

}

}  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = loadXML;  
xmlData.load(“flashbanners/homebanner.xml”);

function changeImage() {

container1.loadMovie(path[0], 1);  
container2.loadMovie(path[1], 1);  
container3.loadMovie(path[2], 1);  
container4.loadMovie(path[3], 1);  
container5.loadMovie(path[4], 1);

}

And then I call that changeImage(); function on each keyframe when a new image container appears. It’s the only way I could figure it out to get it to work this way, although I’m sure there is a better one. Here is the preload script I was trying:

preloader.\_visible = false;

this.onEnterFrame = function() {

//finds out how much of the clip is loaded  
filesize = Math.round(getBytesTotal());  
loaded = Math.round(getBytesLoaded());

//starts the preloader if everything is not loaded yet  
if (loaded != filesize) {  
preloader.\_visible = true;

//preload bar length  
preloader.preload\_bar.\_xscale = 100\*loaded/filesize;

//percentage number  
loaded\_bytes = Math.round(getBytesLoaded());  
loaded\_total = Math.round(getBytesTotal());  
total\_percent = (loaded\_bytes/loaded\_total)\*100;  
preloader.loaded\_text = Math.round(total\_percent);

} else {

preloader.\_visible = false;

}

};

So, is it even possible for a preloader to do that? I got one to work that preloaded each image as it came up, but that’s not the solution I’d like. I appreciate anyone’s input!
