# Loading a random swf

**URL:** <https://forum.kirupa.com/t/loading-a-random-swf/186576>\
**Category:** flash\
**Created:** [April 22, 2006, 3:12pm UTC](https://forum.kirupa.com/t/loading-a-random-swf/186576 "2006-04-22T15:12:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dibble](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@dibble](https://forum.kirupa.com/u/dibble)\
**Post date:** [April 22, 2006, 3:12pm UTC](https://forum.kirupa.com/t/loading-a-random-swf/186576/1 "2006-04-22T15:12:13Z")

</div>

I want to load a random swf from a group of 6. Basically from the intial page i want the user to press a button and this then displays one of the 6 swfs randomly.

I have saved my swf files as numbers 1-6.swf and saved them in a folder called movies. I need to firstly generate a random number between 1 and 6 and then load this corresponding swf file.

Can anyone help me please?

---

<div class="post-metadata">

**Author:** ![Pixeladdict](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Pixeladdict](https://forum.kirupa.com/u/Pixeladdict)\
**Post date:** [April 22, 2006, 3:50pm UTC](https://forum.kirupa.com/t/loading-a-random-swf/186576/2 "2006-04-22T15:50:35Z")

</div>

Well theres this:  
[http://www.kirupa.com/developer/mx/loadingrandombackground.htm](http://www.kirupa.com/developer/mx/loadingrandombackground.htm)

and this:  
[http://www.kirupa.com/developer/actionscript/loading\_random\_movie.htm](http://www.kirupa.com/developer/actionscript/loading_random_movie.htm)

Hope this helps  
pxa

---

<div class="post-metadata">

**Author:** ![dibble](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@dibble](https://forum.kirupa.com/u/dibble)\
**Post date:** [April 23, 2006, 12:59pm UTC](https://forum.kirupa.com/t/loading-a-random-swf/186576/3 "2006-04-23T12:59:43Z")

</div>

Thanks for those pointers but it wasn’t exactly what I wanted to do. I didn’t actually want to have to list all of the swf files instead I wanted to be able to just generate a random number between 1 and 6 which would be the variable “movie” these numbers then correspond to the swf files in the folder. Is it possible to do this please?

---

<div class="post-metadata">

**Author:** ![B\_L\_U\_E](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@B\_L\_U\_E](https://forum.kirupa.com/u/B_L_U_E)\
**Post date:** [April 23, 2006, 4:37pm UTC](https://forum.kirupa.com/t/loading-a-random-swf/186576/4 "2006-04-23T16:37:03Z")

</div>

[AS]function loadSWF():Void {  
max=6, min=1;  
var randomNum:Number = Math.floor(Math.random()\*(max-min+1))+min;  
container.loadMovie(randomNum+".swf");  
}[/AS]🙂
