I am wondering if someone can help me.
I have some actionscript which is designed to randomly load 6 of 18 possible .jpg images into a flash file. The script currently does randomly choose an image six different times, but often the same image will be chosen twice. I need to ensure that if an image is already chosen that it will not be chosen a second time. I am pasting the script that I have below. If you can help me I would be extremely grateful.
newN = 0;
lastN = 0;
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
return randomNum;
}
function getANumber():Number {
x = randRange(0, 18);
return x;
}
function getAnImageIndexNumber () {
while (newN == lastN) {
newN = getANumber();
}
lastN = newN;
return newN;
}
n = getAnImageIndexNumber();
if(n == lastN){
if (n < 17){
n = n + 1;
}else{
n = n – 1;
}
}
debug = true;
_root.onLoad = function(){
images_xml = new XML();
images_xml.ignoreWhite=true;
images_xml.onLoad = parse;
if (debug) {
images_xml.load("images.xml");
} else {
images_xml.load("/logos/images.aspx" + "?cachebuster=" + new Date().getTime());
}
};
function startLoading1(whichImage) {
loadMovie(whichImage, “imageLoader1”);
}
function startLoading2(whichImage) {
loadMovie(whichImage, “imageLoader2”);
}
function startLoading3(whichImage) {
loadMovie(whichImage, “imageLoader3”);
}
function startLoading4(whichImage) {
loadMovie(whichImage, “imageLoader4”);
}
function startLoading5(whichImage) {
loadMovie(whichImage, “imageLoader5”);
}
function startLoading6(whichImage) {
loadMovie(whichImage, “imageLoader6”);
}
function parse(success) {
if (success) {
imageArray = new Array();
var root = this.firstChild;
var imageNode = root.lastChild;
var s=0;
while (imageNode.nodeName != null) {
imageData = new Object;
if (debug) {
imageData.path = imageNode.attributes.path;
} else {
imageData.path = imageNode.attributes.path + “?cachebuster=” + new Date().getTime();
}
imageArray[s]=imageData;
imageNode = imageNode.previousSibling;
s++;
}
imageArray.reverse();
trace(imageArray.length);
n = getAnImageIndexNumber();
startLoading1(imageArray[n].path);
n = getAnImageIndexNumber();
startLoading2(imageArray[n].path);
n = getAnImageIndexNumber();
startLoading3(imageArray[n].path);
n = getAnImageIndexNumber();
startLoading4(imageArray[n].path);
n = getAnImageIndexNumber();
startLoading5(imageArray[n].path);
n = getAnImageIndexNumber();
startLoading6(imageArray[n].path);
} else {
trace(‘problem’);
}
}