Jump to content
Search Community

Multiple SWF loader via buttons

Amnesicat test
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.

Thanks,
Alan

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
  e.currentTarget.SWFLoader.load();
}


function showSwf(e:LoaderEvent) {
   //this simply brings the most recent swf to the top of the display list
   addChild(e.target.content); 
}


//go
createSWFLoaders();

CS6 source attached (use your copy of greensock files)

 

 

loadSwfs_CS6.zip

  • Like 1
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.
×
×
  • Create New...