Hi.
Adding to Nick's suggestion, here is a sample:
AS3 code:
First scene:
import flash.display.SimpleButton;
import flash.events.MouseEvent;
// this check makes sure that everytime the user navigates to this frame the variables won't be reset
if (!this.hasStarted)
{
var allowRepetition:Boolean = false; // set to true or false to allow repetition. If it is set to false, then the code will pick all the scenes in the array before picking the same scene again
var randomScenes:Vector.<String> = new <String> // put the name of your scenes here
[
"Scene 1",
"Scene 2",
"Scene 3",
"Scene 4",
"Scene 5"
];
var count:uint = 0;
this.hasStarted = true;
}
function clickHandler(e:MouseEvent):void
{
if (allowRepetition)
gotoAndStop(1, randomScenes[uint(Math.random() * randomScenes.length)]); // if allowRepetion is set to false, then the code will pick a totally random scene
else
{
if (count % randomScenes.length == 0) // everytime all the scenes are picked, this block of code will randomize the array again
{
randomScenes = randomScenes.sort(function(a:*, b:*):int
{
return ( Math.random() > 0.5 ) ? 1 : -1;
});
}
gotoAndStop(1, randomScenes[++count % randomScenes.length]); // incrementally picks a scene as the array is already sorted
}
}
function setButton(button:SimpleButton):void
{
// Check if the button already has a listener to not add multiple listeneres
if (!button.hasEventListener(MouseEvent.CLICK))
button.addEventListener(MouseEvent.CLICK, clickHandler);
}
stop();
setButton(sceneButton);
Second scene:
stop();
setButton(sceneButton1);
Third scene:
stop();
setButton(sceneButton2);
Fourth scene:
stop();
setButton(sceneButton3);
Fifth scene:
stop();
setButton(sceneButton4);
FLA download:
animate_cc_as3_random_scenes.zip - Google Drive
Regards,
JC