# loadMovie randomly on mouseDown

**URL:** <https://forum.kirupa.com/t/loadmovie-randomly-on-mousedown/18393>\
**Category:** flash\
**Created:** [April 16, 2003, 7:09am UTC](https://forum.kirupa.com/t/loadmovie-randomly-on-mousedown/18393 "2003-04-16T07:09:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariam](https://avatars.discourse-cdn.com/v4/letter/m/b9e5f3/32.png) [@mariam](https://forum.kirupa.com/u/mariam)\
**Post date:** [April 16, 2003, 7:09am UTC](https://forum.kirupa.com/t/loadmovie-randomly-on-mousedown/18393/1 "2003-04-16T07:09:30Z")

</div>

What i’d like to happen. but don’t have enough actionscript knowhow.  
I have a series of small movies. i have made an interface with buttons. when the user presses a button one of the movies will be selected randomly and loaded into the main movie. that’s it.  
Please help.  
best  
m

---

<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:** [April 16, 2003, 7:39am UTC](https://forum.kirupa.com/t/loadmovie-randomly-on-mousedown/18393/2 "2003-04-16T07:39:57Z")

</div>

An idea would be to generate a random number and depending on the number, using ‘if’ statements to see which movie loads…

---

<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:** [April 16, 2003, 8:13am UTC](https://forum.kirupa.com/t/loadmovie-randomly-on-mousedown/18393/3 "2003-04-16T08:13:32Z")

</div>

Well… there’s supposed to be a “switch” method that will accomplish this, but I have no clue how to use it so I’m not going to go into it. There are a number of ways of accomplishing this effect though. I would do it this way:

on the main timeline in one of the first frames place an array constructor like so:

aMovieNames = new Array();  
aMovieNames[0]=“firstMovie.swf”;  
aMovieNames[1]=“secondMovie.swf”;  
aMovieNames[2]=“thirdMovie.swf”;  
aMovieNames[3]=“fourthMovie.swf”;

then on the button all you would need is this

on(release){  
n=Math.round(Math.random()\*\_root.aMovieNames.length);  
\_root.mainMovie.loadMovie(aMovieNames[n]);  
}

given that the instance name of the movie clip which you are loading these into is called “mainMovie”

---

<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:** [April 16, 2003, 11:50pm UTC](https://forum.kirupa.com/t/loadmovie-randomly-on-mousedown/18393/4 "2003-04-16T23:50:59Z")

</div>

thanks Blah-de-blah and david for such a quick reply.  
i just woke up, so i haven’t tried your solution yet. but will try it now  
thanks  
m

---

<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:** [April 17, 2003, 12:42am UTC](https://forum.kirupa.com/t/loadmovie-randomly-on-mousedown/18393/5 "2003-04-17T00:42:43Z")

</div>

Well i tried David’s code and i worked!! thanks david  
but now I have a new weird problem. when the movie loads it seems to load half way down the page, so that you can only see a quarter of the content. it seems to have something to do with the registration of the page? only guessing.  
i’ve checked the alignment of all objects etc. but not sure where page alignment would be? help.m
