# Thread: Start a Random Label Problem

1. Junior Coders
Join Date
Jan 2009
Posts
14
Thanks
0
Thanked 0 Times in 0 Posts

## Start a Random Label Problem

I am running a movie which should start at a random position and follows with a random sequence. The action is placed in frame 1 and all content starts from frame 2. The randomizing works, but only after it plays through "a" frames. For example, it will play a, k e i a f g b j d h c, then continues to randomize the labels. The source of this code was from http://www.quip.net/blog/2007/flash/...ithout-repeats. I'm sure there is something small I am missing, I am new to actionscript. Thanks for any help on making sure this starts in a random position.

Code:
```function shuffle(arr:Array):Void {
var len:Number = arr.length - 1;
for (var i:Number = len; i >= 0; i--) {
var p:Number = Math.floor(Math.random() * (i + 1));
var t:Object = arr[i];
arr[i] = arr[p];
arr[p] = t;
}
}

var labels:Array = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "k"];
shuffle(labels);

var currentLabel:Number = 0;
function gotoNextLabel():Void {
if (currentLabel < labels.length) {
gotoAndPlay(labels[currentLabel]);
currentLabel++;

} else {
shuffle(labels);
currentLabel = 0;
gotoAndPlay(labels[currentLabel]);
currentLabel++;
}
}
gotoNextLabel();```

2. Junior Coders
Join Date
Jan 2009
Posts
14
Thanks
0
Thanked 0 Times in 0 Posts
I've noticed now that it is in Firefox that "a" plays first. In IE, however, it plays the first in the shuffle twice. There is an example here: http://www.every-scene.com. Any ideas?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•