# Playing random movies on load

**URL:** <https://forum.kirupa.com/t/playing-random-movies-on-load/182816>\
**Category:** Uncategorized\
**Created:** [March 21, 2006, 5:18pm UTC](https://forum.kirupa.com/t/playing-random-movies-on-load/182816 "2006-03-21T17:18:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter71](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@Peter71](https://forum.kirupa.com/u/Peter71)\
**Post date:** [March 21, 2006, 5:18pm UTC](https://forum.kirupa.com/t/playing-random-movies-on-load/182816/1 "2006-03-21T17:18:29Z")

</div>

Hello all. I have read through a lot of the forum, though not all, so I am sorry if this is a repeat question, but what I would like to do is load random movies into a SWF on load. So when my swf loads, I would like 1 of 19 movies to reandomly begin playing within a specific area. Anyw help with this would be greatly appreciated. I have just gotten Flash 8, and there are a lot of new techniques that I have not used before. Thanks so much for your time!

Peter

---

<div class="post-metadata">

**Author:** ![BoonDock](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/boondock/32/1188_2.png) [@BoonDock](https://forum.kirupa.com/u/BoonDock)\
**Post date:** [March 21, 2006, 6:09pm UTC](https://forum.kirupa.com/t/playing-random-movies-on-load/182816/2 "2006-03-21T18:09:49Z")

</div>

Make an array and use the names of the movies inside that array and then call the array to load whenever you want it to load the movies and use a random function to load them randomly…

EX:  
[COLOR=“Blue”]myArray = [“movie1.swf”, “movie2.swf”, “movie3.swf”];  
\_root.currMovie = myArray[random(myArray.length)];  
container.loadMovie(\_root.currMovie);[/COLOR]

---

<div class="post-metadata">

**Author:** ![Peter71](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@Peter71](https://forum.kirupa.com/u/Peter71)\
**Post date:** [March 21, 2006, 6:29pm UTC](https://forum.kirupa.com/t/playing-random-movies-on-load/182816/3 "2006-03-21T18:29:05Z")

</div>

Thanks so much man! I will try that out and see how it goes!

---

<div class="post-metadata">

**Author:** ![Soig](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Soig](https://forum.kirupa.com/u/Soig)\
**Post date:** [March 21, 2006, 6:58pm UTC](https://forum.kirupa.com/t/playing-random-movies-on-load/182816/4 "2006-03-21T18:58:37Z")

</div>

I just looked up the same thing myself. Create a movie clip that is 300x300 adn label it “movieTarget”. Then put this code in the timeline. I can’t take credit for this code though. Its a Kirupa original! ;0

> filename = [“circular.swf”, “vibration.swf”, “random\_movement.swf”];  
> path = “[http://www.kirupa.com/developer/actionscript/animation/](http://www.kirupa.com/developer/actionscript/animation/)”;  
> i = filename.length;  
> k = Math.floor(Math.random()\*i);  
> loadMovie(path+filename[k], movieTarget);

---

<div class="post-metadata">

**Author:** ![Peter71](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@Peter71](https://forum.kirupa.com/u/Peter71)\
**Post date:** [March 22, 2006, 2:50pm UTC](https://forum.kirupa.com/t/playing-random-movies-on-load/182816/5 "2006-03-22T14:50:49Z")

</div>

You guys are so cool! Thanks again!

---

<div class="post-metadata">

**Author:** ![Peter71](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@Peter71](https://forum.kirupa.com/u/Peter71)\
**Post date:** [March 23, 2006, 4:30pm UTC](https://forum.kirupa.com/t/playing-random-movies-on-load/182816/6 "2006-03-23T16:30:07Z")

</div>

Hey BoonDock, on this bit, do you put this code within the MC that you are loading the movie? So for instance, I want to target a certain MC to launch the movies in, so would I place this in that MC? I just noticed that you used \_root and I was wondering if that was something that I could change to the instance name of the MC or if I had to place it into the MC itself…

> [@BoonDock](#):
>
> myArray = [“movie1.swf”, “movie2.swf”, “movie3.swf”];  
> \_root.currMovie = myArray[random(myArray.length)];  
> container.loadMovie(\_root.currMovie);

Thanks man -

---

<div class="post-metadata">

**Author:** ![liquify](https://avatars.discourse-cdn.com/v4/letter/l/e95f7d/32.png) [@liquify](https://forum.kirupa.com/u/liquify)\
**Post date:** [March 23, 2006, 4:50pm UTC](https://forum.kirupa.com/t/playing-random-movies-on-load/182816/7 "2006-03-23T16:50:11Z")

</div>

you dont really have to create an array, just put all the swfs in a folder and use this tutorial:  
[http://blog.soromenho.net/?p=18](http://blog.soromenho.net/?p=18)  
(includes a preloader for external swfs)

---

<div class="post-metadata">

**Author:** ![Peter71](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@Peter71](https://forum.kirupa.com/u/Peter71)\
**Post date:** [March 23, 2006, 5:50pm UTC](https://forum.kirupa.com/t/playing-random-movies-on-load/182816/8 "2006-03-23T17:50:40Z")

</div>

> [@liquify](#):
>
> you dont really have to create an array, just put all the swfs in a folder and use this tutorial:  
> [http://blog.soromenho.net/?p=18](http://blog.soromenho.net/?p=18)  
> (includes a preloader for external swfs)

Hey Liquify, that is awesome. One thing that I am running into is that my swf’s are loading flv files externally, so I am randomly loading a swf that is loading another file. Could this be causing a problem with the whole process? Should I embed the video directly into the SWF? Thanks so much to everyone for helping out. You guys are awesome!

Peter
