Jump to content


How One SWF loader loads mulitple swfs with var

Recommended Posts

I thought I knew this....

If I want to load one swf file using SWF loade then I use this line of code:

loader_howToLoader = new SWFLoader("howTo3A_Q90imgs.swf",

If I want to use a SWF loader to load multiple swf files from different buttons.

Then somewhere for all the buttons I have to specify a var, something like this

var sourceVar:String;

But then how do I implement it into the SWF loader code

loader_howToLoader = new SWFLoader("WHAT DO I PUT HERE?",

Link to comment
Share on other sites

from what you've shared, if sourceVar is the actual location of the file


sourceVar = "mySwf.swf";

loader_howToLoader = new SWFLoader(sourcVar, {});


if you use "new SWFLoader()" well then you are createing a new SWFLoader and not re-using the same one


if you are reusing an existing SWFloader


loader_howToLoader.url = sourceVar;
loader_howToLoader.load(true) //load and flush previously loaded content

Link to comment
Share on other sites

I tinkered with the code you have specified and could not come up to the working solution.

I suspect my problem is in properly specifying the


var sourceVar:String;

I assmbled a simplified version of my flash files. The only thing missing are the loading external swfs, which I hope is not an issue.

Please take a look, why can not I replace the loaded swf from other buttons?

Link to comment
Share on other sites

You have mistakes that are causing errors that have nothing to do with the sourceVar being set properly. That is working quite well as you will see if you add


trace("sourceVar " + sourceVar) to frame 5's code in HowTo3A_loadersSwf.


1: in your SWFLoader you have:



yet your callback function is named with a 2.




function completeHandler_howToLoader2(event:LoaderEvent):void{

var loaded_howToLoader:ContentDisplay = event.target.content;

//TweenMax.to(loaded_appLoader, 1.5, {alpha:1, scaleX:1, scaleY:1});//only need this line if corresponding values are changed in SWF loader constructor

TweenMax.to(progressBar_howToLoader_mc, 1.5, {alpha:0, scaleX:0.25, scaleY:0.25});

holderMC_howTo.visible = true;



Also the instance name above in blue is not correct. On frame 5 that symbol has the instance name of holderMC_howTo2 (not sure why this symbol has a different name than on frame 1)


Also, for the container property in your SWFLoader you are using:



but that is the name of the mc on frame 1, NOT frame 5. I think you want to use container:holderMC_howTo2

Link to comment
Share on other sites

Thanks for pointing out my mistakes. I believe I was more careful now and changed all the names properly. At least I do not get any error messages.

However the SWF can be loaded only ones into the SWF loader. Buttons under the loader (at the bottom of the layout) do not reload the new SWF on the page. I have the code specified as

loader_howToLoader = new SWFLoader

so it should be a new loader each time refreshed on the screen, but it doesn't happen?

Link to comment
Share on other sites

I attempted to look at your files.

You provided 5 xfl files in 2 different folders.

Each file has a very cryptic name (to me).

There are no swfs.


I'm sorry, but I can't take the time to try to open up 5 files and guess which one I need and where it should be exported to or how everything needs to be glued together.


I attached the original files with the changes I had suggested to you. They appear to work fine.


If you need any more assistance with this issue you will need to provide very clear files that only contain the code necessary to replicate the problem.

No additional TimelineLite code or effects.

No buttons or code that are unrelated to the problem.

In short, something very easy to open, test and diagnose.


Thanks for understanding.


Link to comment
Share on other sites


I did not realize that my post was so unorganized. I understand and regret that you have spent your time in confusion. I have a sporadic Forums experience, sorry that you happened to be the one to outline the etiquette for me.

I believe that now I have a much more organised and simplified flash file.

You will see in my folder the file named "main_openThis"

The problem is that grey buttons numbered 1-4 do not reload a new swf in the loader above.

I have the code specified as

 loader_howToLoader = new SWFLoader 

so it should be a new loader each time refreshed on the screen, but it doesn't happen?

Link to comment
Share on other sites

hi, the new files are a huge improvement. thank you.


the problem was you were setting the sourceVar, but weren't doing anything to make the SWFLoader load. For buttons 3 and 4, you were already on the section2 frame which creates the SWFLoader. setting the soureVar after the SWFLoader is created won't do anything unlesss you also re-create the SWFLoader with the new sourceVar when the button is clicked.


the code below shows how buttons 3 and 4 are now configured



Button3.addEventListener(MouseEvent.CLICK, Button3_PlayPopUp);

function Button3_PlayPopUp(event:MouseEvent): void {

loader_howToLoader2.url = sourceVar;


Button4.addEventListener(MouseEvent.CLICK, Button4_PlayPopUp);

function Button4_PlayPopUp(event:MouseEvent): void {
loader_howToLoader2.url = sourceVar;



Normally I would wrap the code that creates a new SWFLoader or changes the url property in a function that can be re-used. I didn't want to implement anything that would require changing other aspects of your file.


see the attached fla which should have buttons 1-4 all working. just save it into the folder you provided to me.


Link to comment
Share on other sites


I was able to use your suggestion. Everything works perfectly now. Thanks a lot for your help!

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.