I created a script to load a picture slider using an XML database to load the pictures. Does anyone know how to create a dynamic preloader that will reveal the pictures once all of them have fully loaded? The code is written below:

Code:
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("food.xml");
/////////////////////////////////////
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
widths = [];
totalwidths = [];
totalwidths[0] = 0;
piclocation = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
widths[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
}
for (i=0, count=0, j=1; i<total; i++, j++) {
y = widths[i] - 0;
count = count+ y + 3;
totalwidths[j] = count;
}
loadimages();
}
};
function loadimages() {
widths = [];
var totalwidth = 0;
for (i=0;i<total; i++) {
var picref = this.createEmptyMovieClip("container"+i,i);
picref.loadMovie(image[i]);
}
setLocation();
};
function setLocation() {
for (i=0; i<total; i++) {
var contain = "container"+i;
setProperty (contain,_x,totalwidths[i]);
}
};
////////////////// button functions
this.onEnterFrame = function() {
var rightposition = (700 - 344 - totalwidths[total]);
if (_root.nav.contents._x >= -344) {
tellTarget ("_level0.nav.scroller.scroll_right") {
gotoAndStop(1);
enabled = false;
}
} else {
tellTarget ("_level0.nav.scroller.scroll_right") {
enabled = true;
}
}
if (_root.nav.contents._x <= rightposition) {
tellTarget ("_level0.nav.scroller.scroll_left") {
gotoAndStop(1);
enabled = false;
}
} else {
tellTarget ("_level0.nav.scroller.scroll_left") {
enabled = true;
}
}
};