Jump to content


Multiple SWF loader via buttons

Moderator Tag

Recommended Posts

Hello there,

I would really like some guidance on the best approach for loading multiple SWFs via an array of buttons ie. each button loads a different SWF url. Should I use a Loadermax parse?, if so, how exactly should I go about it?

Any example code would be greatly appreciated.


Link to comment
Share on other sites

Its difficult to know what the best way would be without knowing more about your project.

The basic mechanics of what you need are fairly straight-forward. The example below requires that you have an Array of btns and an Array of urls for each swf.

Hopefully the comments suffice:


import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import flash.events.MouseEvent;

//this is an array of buttons
var btnsArray:Array = [btn0, btn1];

//this is an array of urls of swfs to load
var swfsArray:Array = ["swf1.swf", "swf2.swf"];

function createSWFLoaders() {
for (var i:int = 0; i<swfsArray.length; i++) {
//create a SWFLoader for each button
//the url of swf to load is swfsArray[i]
btnsArray[i].SWFLoader = new SWFLoader(swfsArray[i], {container:this, onComplete:showSwf});
//tell each button to call loadSwf when clicked
btnsArray[i].addEventListener(MouseEvent.CLICK, loadSwf);

function loadSwf(e:MouseEvent): void {
 //load the swf based on the button that was clicked

function showSwf(e:LoaderEvent) {
   //this simply brings the most recent swf to the top of the display list


CS6 source attached (use your copy of greensock files)




  • Like 1
Link to comment
Share on other sites

This is great, thanks a lot Carl. I just needed a basic example to build on, and this should fit the bill nicely.


Also, I just wanted to say that you guys are doing are terrific job and are always so very helpful.




Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.