# Go To Random Scene

**URL:** <https://forum.kirupa.com/t/go-to-random-scene/9538>\
**Category:** flash\
**Created:** [December 13, 2002, 4:07pm UTC](https://forum.kirupa.com/t/go-to-random-scene/9538 "2002-12-13T16:07:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_Boy](https://avatars.discourse-cdn.com/v4/letter/t/13edae/32.png) [@T\_Boy](https://forum.kirupa.com/u/T_Boy)\
**Post date:** [December 13, 2002, 4:07pm UTC](https://forum.kirupa.com/t/go-to-random-scene/9538/1 "2002-12-13T16:07:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 4:36pm UTC](https://forum.kirupa.com/t/go-to-random-scene/9538/2 "2002-12-13T16:36:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 4:41pm UTC](https://forum.kirupa.com/t/go-to-random-scene/9538/3 "2002-12-13T16:41:48Z")

</div>

Thank you - I wil give it a try!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2002, 4:51pm UTC](https://forum.kirupa.com/t/go-to-random-scene/9538/4 "2002-12-13T16:51:40Z")

</div>

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.
