Jump to content
Search Community

Can I load multiple SWFiles into SWF Loader from different pages?

ngrinchenko test
Moderator Tag

Recommended Posts

Hi,

I have a page with various image buttons (page1). From this page I am accessing another page (page2) where greensock's SWF loader is constructed and loads multiple SWFs from the first page (page1). These larger SWFs are corresponding to various buttons on the first page (page1).

For that I have set up a var on page1:

 

var sourceVar_ProductsPopUps:String;

then each button has a code like this:

then I use this var in all the buttons

 

function onClickSumix16RGBPopUp(event:MouseEvent) :void {
sourceVar_ProductsPopUps="prdcts_popups/Sumix16RGB-popup_tl.swf";
gotoAndPlay("(page2");
}

 

Then this var is used in the SWF loader construction on page2:

loaderProductPopUps = new SWFLoader(sourceVar_ProductsPopUps,

 

 

Then I wanted to have additional buttons on page2 and load other SWF files into that same SWF loader on page2.

So I used the same code. I made a button and this is my script from a button on page2:

 

tryDelete_mc.addEventListener(MouseEvent.CLICK, onClicktryDelete_mc);


function onClicktryDelete_mc(event:MouseEvent):void {sourceVar_ProductsPopUps = event.currentTarget.prop;
}

 

Why it doesn't work in the second case?

Link to comment
Share on other sites

I'm sorry but I'm a little lost by what you mean by page1 and page2.

There could be any number of issues at play here.

have you put trace statements in your functions to see if they are actually running?

Can you confirm that you are attempting to load the swfLoader after you set the source var?

 

Its very difficult to trouble shoot this from just a few lines of code.

Link to comment
Share on other sites

Sorry for not a clear description. By page1 and page2 I meant sections of my webstie, which are labeled. For a presumed convenience of not writing out a label name I called them page1 and page2.

Here is what is going on on the website section labeled "page1"

var sourceVar_PopUps:String;
//////////////1_btn
btn1.addEventListener(MouseEvent.CLICK, onClick1PopUp);
function onClick1PopUp(event:MouseEvent) :void {
sourceVar_PopUps="prdcts_popups/1btn-popup_tl.swf";
gotoAndPlay("page2");
 }
//////////////2_btn
btn2.addEventListener(MouseEvent.CLICK, onClick2PopUp);
function onClick2PopUp(event:MouseEvent) :void {
sourceVar_PopUps="prdcts_popups/2btn-popup_tl.swf";
gotoAndPlay("page2");
 }

 

Then on "page2" I have this code for constructing SWF loader:

var loaderProductPopUps:SWFLoader;

if (loaderProductPopUps){
if(loaderProductPopUps.content){
  loaderProductPopUps.unload();
}
}

loaderProductPopUps = new SWFLoader(sourceVar_PopUps, //the value of sourceVar_PopUps allows to load mulitple SWFs from the products page.
	  {
	  estimatedBytes:5000,
	  container:holderMovieClip,// more convinient and easier to manage if to place the LoaderMax into an empty mc (holderMovieClip)
			  // if not will work as well. Then the line container:holderMovieClip, has to be replaced with container:this,
			  // can be any size, can not be scaled as it distorts the content
	  onProgress:progressHandler,
	  onComplete:completeHandler,
	  centerRegistration:true,
	  //x:-260, y:-320, //no need for this is if used: centerRegistration:true,
	  alpha:1,
	  scaleMode:"none",
	  //scaleX:0, scaleY:0,
	  //vAlign:"top",
	  width:540,
	  height:730,//scales proportionally but I need to cut off the edges
	  crop:true,
	  autoPlay:false
	  });
function progressHandler(event:LoaderEvent):void{
progressBarPopUp_mc.gradientbar_appLoader_mcPopUp_mc.scaleX = loaderProductPopUps.progress;
}
function completeHandler(event:LoaderEvent):void{
var loadedImage:ContentDisplay = event.target.content;
//TweenMax.to(loadedImage, 1.5, {alpha:1, scaleX:1, scaleY:1});//only need this line if corresponding values are changed in SWF loader constructor
TweenMax.to(progressBarPopUp_mc, 1.5, {alpha:0, scaleX:0.25, scaleY:0.25});
}
loaderProductPopUps.load();

 

So far everything works,

Then I decided to add a new set of buttons in "page2" and can not load an SWF into SWF loader any more from "page2"

 

Here is the sample code for the buton named "tryDelete_mc":

 

tryDelete_mc.alpha = 0.15;
 var  tryDelete_mc_Tween:TweenLite = TweenLite.to(tryDelete_mc, .5, {alpha:1, paused:true});

 tryDelete_mc.addEventListener(MouseEvent.ROLL_OVER, overHandler_tryDelete_mc);
 tryDelete_mc.addEventListener(MouseEvent.ROLL_OUT, outHandler_tryDelete_mc);

	tryDelete_mc.addEventListener(MouseEvent.CLICK, onClicktryDelete_mc);


function onClicktryDelete_mc(event:MouseEvent):void {
 sourceVar_PopUps="prdcts_popups/tryDelete-popup_tl.swf";
 trace("you clicked on me");
  }



function overHandler_tryDelete_mc(e:MouseEvent):void{
	 tryDelete_mc_Tween.play();
	 trace("you rolled over me");
	 }

function outHandler_tryDelete_mc(e:MouseEvent):void{
	 tryDelete_mc_Tween.reverse();
	 trace("you rolled off me");
	 }

 

All traces work, so I do not know why I can not load on "page2" if I can do it from "page1" ?

Link to comment
Share on other sites

Thanks for the additional explanation.

 

I see you added trace() statements for the various mouse events on tryDelete_mc. I don't see when you click tryDelete_mc it looks like you are missing code that actually calls

 

loaderProductPopUps.load();

 

after you set the soureVar_PopUps url you need to tell the SWFLoader to load the new file.

Link to comment
Share on other sites

Thanks for looking into the code.

I tried to implement what you have suggested and it looks like it starts to go into right direction.

Unfortunately due to my lack of scripting knowledge I only was able to make "tryDelete_mc" button to load a previously loaded SWF again ( I have no idea what to do after that)

So it loads something but not what I need.

I made a sample flash file with my troubles.

Please take a look at it (there is bare minimum of code).

What did I do wrong?

Link to comment
Share on other sites

Hi, I commend you on your efforts to supply a simplified file. Thank you very much. It really made finding the issue quite painless.

 

replace your onClicktryDelete_mc function with this:

 

 

function onClicktryDelete_mc(event:MouseEvent):void {
 sourceVar_PopUps="loadedSWF3.swf";
 //change the url of the SWFLoader
 loaderProductPopUps.url = sourceVar_PopUps;
 //load the new swf and flush out the old swf
 loaderProductPopUps.load(true);
 trace("you clicked on tryDelete_mc");
  }

 

I think you will find that you can now load swf3 whenever the opportunity arises.

 

Best,

 

Carl

Link to comment
Share on other sites

the problem is that when the first swf finishes loading you hide the progressbar:

 

 

function completeHandler(event:LoaderEvent):void{
var loadedImage:ContentDisplay = event.target.content;
//TweenMax.to(loadedImage, 1.5, {alpha:1, scaleX:1, scaleY:1});//only need this line if corresponding values are changed in SWF loader constructor
TweenMax.to(progressBarPopUp_mc, 1.5, {alpha:0, scaleX:0.25, scaleY:0.25});
}

 

you are setting the alpha to 0 and then you never show it. the reason it works when you load swf 1 and 2 is because you are jumping back and forth between keyframes each time you load a new swf.

 

make sure when you click the button to load swf3 that the progress bar is in the right starting state concerning alpha, scaleX, scaleY etc.

Link to comment
Share on other sites

Hi, thanks for helping out.

Most probably with my next question I am overstepping help scope of this forum. I understand if you will not answer.

But emboldened by success with your help I wanted to add the functionality and construct a scrolling thumb gallery. So I found the tutorial which builds jpg row out of xml file. I was able to modify it with tweenMax transitions.

And got stock on linking everything properly.

Below is the code in AS panel. I am not sure how to do it so it loads into SWF loader.

 

function clickScrollerItem(e:MouseEvent):void {
//trace("clicked item " + e.currentTarget.itemNum + " - visit url: " + e.currentTarget.link);
var urlRequest:URLRequest = new URLRequest(e.currentTarget.link);
try {
 navigateToURL(urlRequest);
}
catch (e:Error) {
 // handle error here
 trace(e);
}
}

 

and here is the line of code from xml file. I suppose I can still leave it as URL and just change jpg file into swf ?

 

<image src="images/tn/madness_arch2.jpg" title="Arch 2" url="images/madness_arch2.jpg" />

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