Share Posted September 19, 2014 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 More sharing options...
Share Posted September 19, 2014 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 1 Link to comment Share on other sites More sharing options...
Author Share Posted September 20, 2014 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. Cheers, Alan Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now