Random frame names

Anyone have any code handy that will randomly select a frame name and play that section?

Basically I want a section to play, then upon the last frame in that section a code will be executed to randomly select another frame name(section).

  1. Make an array with your frame names
  2. Randomly choose one from the array
  3. gotoAndPlay(the chosen name);

There might be some trouble in going to the value of a variable so in that case look into the eval() function.

Something like this should work:

var frames:Array = ['coolFrame', 'neatFrame', 'awesomeFrame', 'wowFrame', 'niceFrame'];
gotoAndPlay(frames[Math.floor(Math.random()*frames.length)]);

You shouldn’t need to worry about using eval. When moving the playhead to a labeled frame, gotoAndPlay accepts a string as the only parameter, and the elements of the array are all strings.

That’s perfect man, thanks.