Flash Random Scene ActionScript
I recently created a Flash Animation that would randomly play one of three different Flash scenes. Then after each scene, it would go back to the beginning and randomly choose another scene to play. This was all programmed in ActionScript in Flash.I have a feeling that even though this code is very simple, it will save a little bit of time if I have it stored here for the future.
// First Choose a random numberThat's it!
//from 0 to the number of scenes
num = random(3);
//Depending on which random number
//was chosen, go to a flash scene
switch (num)
{
case 0:
gotoAndPlay("scenename", 1);
break;
case 1:
gotoAndPlay("scenename1", 1);
break;
case 2:
gotoAndPlay("scenename2", 1);
break;
default:
trace ( " no case tested true " )
}
-Ashton Sanders
Labels: ActionScript, Ashton Sanders, Flash



2 Comments:
hi ashton, looks good i was looking some like this. where do we put this script? in the first scene?
Hi,
Yes. Make the first scene a blank screen, and put this code in one of the frames.
Then have the end of each of your scenes redirect back to the beginning of the first scene.
Post a Comment
<< Home