I want to make a navigation bar that loads image buttons randomly. Ex: (you can see the non-random version at the bottom of the page on www.brewerthompson.com/lies) I have 5 slots. I want to randomly load an external swf into an empty button in each of the slots. I do not want the same button to load in more than one slot. I’m thinking I need to use arrays? (which I don’t know too much about.) Can anyone point me to a useful tutorial? Give me advice? Thanks!
I have made a small script that generates unique set of random numbers… In this example, it makes an array called slots and the values are allways from 0 to max-1 that is 9 here.
var max:Number = 10;
var howMany:Number = 5;
var slots:Array = new Array();
for (i=0; i<howMany; i++) {
var randomNumber:Number = Math.floor(Math.random()*max);
if (slots.length == 0) {
slots.push(getRandomNumber());
} else {
do {
randomNumber = getRandomNumber();
if (isUnique(randomNumber)) {
slots.push(randomNumber);
break;
}
} while (false);
}
}
function getRandomNumber():Number {
return Math.floor(Math.random()*max);
}
function isUnique(x:Number):Boolean {
for (i=0; i<slots.length; i++) {
if (x == slots*) {
return false;
}
}
return true;
}
trace(slots);
You can then use it as for example:
slot0.loadMovie("someFile_" + slots[0] + ".swf");
slot1.loadMovie("someFile_" + slots[1] + ".swf");
slot2.loadMovie("someFile_" + slots[2] + ".swf");
slot3.loadMovie("someFile_" + slots[3] + ".swf");
slot4.loadMovie("someFile_" + slots[4] + ".swf");