Log in

View Full Version : Start a Random Label Problem



megs1328
06-11-2009, 08:55 PM
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/how-to-jump-randomly-to-frame-labels-without-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.



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();

megs1328
06-12-2009, 09:58 PM
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?