# Loading random swf files

**URL:** https://forum.kirupa.com/t/loading-random-swf-files/315891
**Category:** flash
**Created:** [November 7, 2010, 12:57am UTC](https://forum.kirupa.com/t/loading-random-swf-files/315891 "2010-11-07T00:57:17Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Lotuseye](https://avatars.discourse-cdn.com/v4/letter/l/ee7513/32.png) [@Lotuseye](https://forum.kirupa.com/u/Lotuseye)
#### Post date: [November 7, 2010, 12:57am UTC](https://forum.kirupa.com/t/loading-random-swf-files/315891/1 "2010-11-07T00:57:17Z")

</div>

I have code that plays a random swf file from an array.

stop();  
var movieArray:Array = [‘home lotus’,‘recall’,‘doors’];

var loader:Loader = new Loader();  
var index:int = movieArray.length \* Math.random();  
var url:String = movieArray[index] + ‘.swf’;  
trace(“Attempting to load”, url);  
loader.load(new URLRequest(url));  
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);  
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO\_ERROR, loaderIOError);  
addChild(loader);

function loaderComplete(e:Event):void {  
trace(“Successfully loaded”, url);  
}  
function loaderIOError(e:IOErrorEvent):void {  
trace(“Failed to load”, url);  
}

essentially, I want to be able to load the movie with a button.

Click–\>load random swf file

any help would be awesome
