Hi there,

I'm using Flash CS3 and would like to create an image gallery that randomly loads images listed in an XML file without repeating any of the images until all have been displayed once.

So far, I've managed to combine a couple of tutorials to create an image gallery that randomly loads images from an XML file, but images often repeat before all images have been displayed once (there are over 2 dozen images). Here's the code:

Code:
delay = 3000;

function loadXML(loaded) {
	if (loaded) {
		xmlNode = this.firstChild;
		image = [];
		description = [];
		total = xmlNode.childNodes.length;
		for (i=0; i<total; i++) {
			image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
			description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
		}
		firstImage();
	} else {
		content = "file not loaded!";
	}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("images.xml");
p = 0;
this.onEnterFrame = function() {
	filesize = picture.getBytesTotal();
	loaded = picture.getBytesLoaded();
	preloader._visible = true;
	if (loaded != filesize) {
		preloader.preload_bar._xscale = 100*loaded/filesize;
	} else {
		preloader._visible = false;
		if (picture._alpha<100) {
			picture._alpha += 10;
		}
	}
};
function nextImage() {
var ranNum = Math.floor(Math.random()*image.length);
trace(image[ranNum]);
	if (p<(total-1)) {
		p++;
		if (loaded == filesize) {
			picture._alpha = 0;
			picture.loadMovie(image[ranNum],1);
			slideshow();
		}
	}
}
function prevImage() {
var ranNum = Math.floor(Math.random()*image.length);
trace(image[ranNum]);
	if (p>0) {
		p--;
		picture._alpha = 0;
		picture.loadMovie(image[ranNum], 1);
	}
}
function firstImage() {
var ranNum = Math.floor(Math.random()*image.length);
trace(image[ranNum]);
	if (loaded == filesize) {
		picture._alpha = 0;
		picture.loadMovie(image[ranNum], 1);
		slideshow();
	}
}
function slideshow() {
	myInterval = setInterval(pause_slideshow, delay);
	function pause_slideshow() {
		clearInterval(myInterval);
		if (p == (total-1)) {
			p = 0;
			firstImage();
		} else {
			nextImage();
		}
	}
}
I've spent days sifting through help forums and tutorials trying to learn how to do this and haven't been successful. Thought I would ask for a hand. Any help is very much appreciated!

Thank you, kindly!