1 Reply Latest reply on May 24, 2007 1:28 PM by Greg Dove

    Stepping through a shuffled array

      I have 15 movie clips in my Flash file, each located on a different frame of the main timeline. Each of these frames has been given a label: "a" through "o". I need the Flash to play each of these labeled frames in a random order, not allowing any one frame to repeat until all the others have played through once.

      In other words, the Flash will first jump to a random frame, allow the associated movie clip to play, and then an actionscript at the end of that clip will tell the main timeline to jump to a new random frame, and so on until all 15 clips have played.

      Once this has occurred, the order of the frames will be shuffled again and we'll repeat.

      I started by creating an array of all the frame labels and then creating a function to select one at random:

      function getRandomLabel():String {
      var labelArray:Array = new Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o");
      var index:Number = Math.floor(Math.random() * labels.length);
      return labelArray[index];

      Then at the end of each movie clip, I added:


      That solves half the problem, but doesn't address the no-repeating issue. I think what I really need to do is shuffle the array and then have the movie play through the frames in that shuffled order. Once all 15 frames have played, the array will be reshuffled and the frames will play through in this new order.

      I just can't seem to figure out how to do that. Any help would really be appreciated.