Go To Random Scene

Hi Flash experts!

I would be very grateful if someone could let me know if, and if so, how you write the action scripting for the last frame of a pre-loader, to make your movie just go to any one of the scenes in the movie at random.

Hope that makes sense.

Many thx in advance,
T.

Give each of your scenes a number for a name (like 1, 2, 3, 4 , 5, etc).

Now declare a variable.

Let’s call it changeScene for this example.

Now you want a random number to choose from to change your scene…

changeScene = Math.floor(Math.random()*5+1)

Now you want to use that produced number to go to your scene

_root.gotoAndPlay(changeScene, 1);

I THINK that should work…lol.

Thank you - I wil give it a try!!

If that doesn’t work you might be able to try holding it in an array…

myArray = [“1”, “2”, “3”, “4”, “5”];
changeScene = Math.floor(Math.random()*5);
_root.gotoAndPlay(myArray[changeScene], 1);

Where myArray is the array that holds all the names of your Scenes.

changeScene pics out a random number from 0 to 4 (since Arrays start counting at 0)

Then the gotoAndPlay says to choose the name in myArray that is in the position of the number produced by changeScene. So is changeScene produces a 3, it will pic out the name in position 3, which would be “4” (count “1” as 0 and keep counting to the right). So it will come out as _root.gotoAndPlay(myArray[3], 1) which in turn will interpret into _root.gotoAndPlay(“4”, 1)

Of course you don’t have to use numbers as names, with an array, you can actually name your scenes.