# I want to make a randomly loading nav bar

**URL:** https://forum.kirupa.com/t/i-want-to-make-a-randomly-loading-nav-bar/185610
**Category:** flash
**Created:** [April 14, 2006, 5:32pm UTC](https://forum.kirupa.com/t/i-want-to-make-a-randomly-loading-nav-bar/185610 "2006-04-14T17:32:04Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![carathompson](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@carathompson](https://forum.kirupa.com/u/carathompson)
#### Post date: [April 14, 2006, 5:32pm UTC](https://forum.kirupa.com/t/i-want-to-make-a-randomly-loading-nav-bar/185610/1 "2006-04-14T17:32:04Z")

</div>

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](http://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!

---

<div class="post-metadata">

### Author: ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)
#### Post date: [April 14, 2006, 7:11pm UTC](https://forum.kirupa.com/t/i-want-to-make-a-randomly-loading-nav-bar/185610/2 "2006-04-14T19:11:48Z")

</div>

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.

```auto
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:

```auto
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");

```
