PDA

View Full Version : Load multiple SWFs



alemieux34
September 14th, 2007, 10:02 AM
I'm using the loader class to load some SWF files. I have 5 buttons that will load 5 movies. Here's my code:


// Make loader initially invisible
loader.visible = false;
b1.addEventListener(MouseEvent.CLICK, swf1);
function swf1(event:MouseEvent):void {
var swf1Ldr:Loader = new Loader();
var swf1URL:String = "dieHard.swf";
var swf1URLReq:URLRequest = new URLRequest(swf1URL);
swf1Ldr.load(swf1URLReq);
swf1Ldr.contentLoaderInfo.addEventListener(Event.C OMPLETE, swf1Loaded);
function swf1Loaded(event:Event):void {
holder.addChild(swf1Ldr.content);
}
// Make the progress clip visible and show the progress loaded
swf1Ldr.contentLoaderInfo.addEventListener(Progres sEvent.PROGRESS, swf1Progress);
function swf1Progress(event:ProgressEvent):void {
loader.visible = true;
var percent:Number = event.bytesLoaded/event.bytesTotal * 100;
loader.percent.text = Math.round(percent) + "%";
loader.loader_mc.scaleY = percent/100;
if (percent>=100) {
loader.visible = false;
}
}
}


Is there any way to slim this down and condense it? For example, could I write an array to point to all of the swfs I'm loading and then point to the array value from the button to load that specific SWF. Otherwise, I'm going to repeat this code 5 times.