Jump to content
Search Community

How to apply remove from stage for LoaderMax?

ngrinchenko test
Moderator Tag

Recommended Posts

My Set Up:LoaderMax is the placement for various individual SWFs. Each time it loads a unique URL depending on which button is clicked from the products page.

If I navigate from the labeled section with LoaderMax the SWF which was just loaded is still on the page, even-though I navigated to a different labeled section.

 

What would be a code to clean it off the stage?

Link to comment
Share on other sites

Hey ya mate,

 

If I'm understanding you right, you want to clear the old clip before you load in a new one? If thats the case its not really a LoaderMax issue but more the way Flash handles objects in its display list.

If you are loading your movies/images etc into an empty movieclip or sprite its faily easy to do:

 

while (holderMovieClip.numChildren > 0)
{
   holderMovieClip.removeChildAt(0);
}

 

The will remove any old clips in your holder movieclip, if you stick this just before you load in a new clip in your code, it should remove it before it places the new loaded clip in.

Link to comment
Share on other sites

Not exactly the case.

My LoaderMax SWF stays on the stage even if I move to another label, and then another label and so on...

I am at the beginning stage of my learning with AS3 and GreenSock, so sometimes obvious things are not obvious to me

 

I implemented the code provided by Zync but it throughs the errors

 

 

Here is my complete code

var loaderProductPopUps:SWFLoader = new SWFLoader("prdcts_popups/sumix1-popup_tl.swf", {
									   estimatedBytes:5000, 
									   container:this, 
									   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:520, 
									   height:690,//scales proportionally but I need to cut off the edges
									   crop:true,
									   autoPlay:false
									   });

function progressHandler(event:LoaderEvent):void{
progressBarPopUp_mc.gradientbarPopUp_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});  
TweenMax.to(progressBarPopUp_mc, 1.5, {alpha:0, scaleX:0.25, scaleY:0.25}); 
}

loaderProductPopUps.load();

 

What would be a full line to implement the

loaderProductPopUps.unload();

line of code.

Also does it go on the same frame in the main time line where the LoadeMax instance is placed or into each individual loaded SWF?

Link to comment
Share on other sites

loaderProductPopUps.unload();

 

that is exactly the full line of code that you need to unload() a SWFLoader. you want to use it before the next swf loads. it goes in the same file that creates the SWFLoader.

 

be sure you only use it after you have created a loaderProductPopUps SWFLoader. you can do something like

 

if(loaderProductPopUps){
loaderProductPopUps.unload()
}

 

to make sure it isn't trying to unload something before it has been created.

Link to comment
Share on other sites

Not exactly the case.

I implemented the code provided by Zync but it throughs the errors

 

var loaderProductPopUps:SWFLoader = new SWFLoader("prdcts_popups/sumix1-popup_tl.swf", {
									   estimatedBytes:5000, 
									  container:this, ////////////////////////CONTAINER//////////////////////////////// make an empty movieclip called 'holderMovieClip' and pass reference here
									   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:520, 
									   height:690,//scales proportionally but I need to cut off the edges
									   crop:true,
									   autoPlay:false
									   });

 

The best way would be to load your swf into an empty movieclip or sprite. Load stuff directly to the stage (while that works just fine) I've always found it to be less convenient and harder to manage than if it was just in its own empty container. Then depending on what you call the container, you can use the While loop.

 

And hey ya Carl, yeah its been a while. Finally back from holiday and really want to start getting some game tuts out again for 'gaming with greensock'

Link to comment
Share on other sites

Hey ya mate,

Your suggestion to use the movie clip container just works. Surprisingly (to me) just the fact that I am placing all my loaded SWF into a movie clip container automatically solved the problem of removing the loaded SWF from stage. It just does.

But movie clip container gives me another issue, all my SWF's are stretched vertically. I tried a few things which made sense to me but none of them worked and all of the SWFs loaded are still stretched vertically.

 

Additional issue. If I am applying your original code

while (holderMovieClip.numChildren > 0)
{
   holderMovieClip.removeChildAt(0);
}

which I place at the same frame after the LoaderMax so the entire code looks like this:

var loaderProductPopUps:SWFLoader = new SWFLoader(sourceVar_ProductsPopUps, //the value of sourceVar_ProductsPopUps allows to load mulitple SWFs from the products page.
									{
									estimatedBytes:5000, 
									container:holderMovieClip, 
									onProgress:progressHandler,
									onComplete:completeHandler,
									centerRegistration:true,
									alpha:1, 
									scaleMode:"none",
									width:540, 
									height:690,
									crop:true,
									autoPlay:false
									});

function progressHandler(event:LoaderEvent):void{
progressBarPopUp_mc.gradientbarPopUp_mc.scaleX = loaderProductPopUps.progress;
}

function completeHandler(event:LoaderEvent):void{
var loadedImage:ContentDisplay = event.target.content;
TweenMax.to(progressBarPopUp_mc, 1.5, {alpha:0, scaleX:0.25, scaleY:0.25}); 
}

loaderProductPopUps.load();

///////////////////////////////////

while (holderMovieClip.numChildren > 0)
{
   holderMovieClip.removeChildAt(0);
}

 

It seems to unload the SWFs right away.... so I end up with an empty screen.

 

Do I place the code in the right place?

Do I have to create some other handle or variable which executes the code when it is needed?

 

 

Carl,

I was not able to use your code as well. It seems to unload the loaded SWF immediately, so I end up with an empty screen. Here is the code you have provided located at the end of my LoaderMax contractor:

var loaderProductPopUps:SWFLoader = new SWFLoader(sourceVar_ProductsPopUps, //the value of sourceVar_ProductsPopUps allows to load mulitple SWFs from the products page.
									{
									estimatedBytes:5000, 
									container:holderMovieClip,
									onProgress:progressHandler,
									onComplete:completeHandler,
									centerRegistration:true,
									alpha:1, 
									scaleMode:"none",
									width:540, 
									height:690,
									crop:true,
									autoPlay:false
									});

function progressHandler(event:LoaderEvent):void{
progressBarPopUp_mc.gradientbarPopUp_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();

///////////////////////////////////
if(loaderProductPopUps){
loaderProductPopUps.unload()
}

 

It is all located on one frame.

Do I place the code in the right place?

Do I have to create some other handle or variable which executes the code when it is needed?

Link to comment
Share on other sites

yes, in my code unload() will work immediately when its called. if you have it working, don't worry about trying to mix my code with zyncs with yours. it is getting very difficult to follow.

 

if all of your movieclips are being vertically scaled, make sure the container clip hasn't been accidentally transformed.

Link to comment
Share on other sites

Hi Carl,

Thanks for the suggesting that there should be a scale somewhere on the container clip. It exactly what it was. Somehow it was a scale set in the transform options. Once everything set to 100% everything looks as it should be.

 

As for unloading the SWF I would like to make sure I implemented your code properly. Somehow I got this idea that the code:

if(loaderProductPopUps){
loaderProductPopUps.unload()
}

 

Has to be located on the same frame as the LoaderMax which made the unloading immediate so I ended up with an empty screen.

Once I put this line of code on other sections to which a user navigate from the section with the LoaderMax, everything works.

It does seem a bit cumbersome that the same code has to be implemented repeatedly throughout the site, i.e. on as many sections as to which a user can navigate from the page with the LoaderMax.

So just wanted to make sure if I was supposed to implement the "clearing the loaded SWF from the stage" code in the same frame as the LoaderMax?

 

I understand, it is getting convoluted. If I will not be able to resolve it I will start a new thread with just one direct question.

As the last follow up I wanted to ask you on the proper implementing of your code only.

The code you have provided is:

if(loaderProductPopUps){
loaderProductPopUps.unload()
}

 

Presently it works as if it unloads the content of "loaderProductsPopUps" right away.

Could you please let me know if any specific handle, variable or any other type of command has to be implemented in order for the unloading to take a place only when it is needed, i.e. when I leave the section with the "loaderProductsPopUps"?

Here is the entire code located on the frame with the LoaderMax:

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.*;

progressBarPopUp_mc.gradientbarPopUp_mc.scaleX = 0;


var loaderProductPopUps:SWFLoader = new SWFLoader(sourceVar_ProductsPopUps,
									{
									estimatedBytes:5000, 
									container:this, 
									onProgress:progressHandler,
									onComplete:completeHandler,
									centerRegistration:true,
									alpha:1, 
									scaleMode:"none",
									width:540, 
									height:690,
									crop:true,
									autoPlay:false
									});

function progressHandler(event:LoaderEvent):void{
progressBarPopUp_mc.gradientbarPopUp_mc.scaleX = loaderProductPopUps.progress;
}

function completeHandler(event:LoaderEvent):void{
var loadedImage:ContentDisplay = event.target.content;
TweenMax.to(progressBarPopUp_mc, 1.5, {alpha:0, scaleX:0.25, scaleY:0.25}); 
}

loaderProductPopUps.load();


if(loaderProductPopUps){
loaderProductPopUps.unload()
}

Link to comment
Share on other sites

loaderProductPopUps.load();

if(loaderProductPopUps){
loaderProductPopUps.unload()
}

 

if you load() something and then in the next lines of code unload() it; the thing that you loaded is going to go away immediately.

you want to put the code to unload the existing content somewhere BEFORE you load the new content.

 

in your case perhaps at the top of your script on each frame or in the functions that use to go to the next or previous frames.

 

Yes having the same code on multiple frames can be quite cumbersome which is why it is recommended to put as much code as possible in 1 frame or in external files, that would take a good deal of restructuring right now and it could be too early in the learning process to understand all that. I suggest you keep at it, keep reading tutorials and perhaps get a few books. it will get easier.

Link to comment
Share on other sites

Thanks, Carl.

It does get easier. I started with my small steps searching the web and have to say your tutorials on snorkl.tv provided a great help.

I find them the most concise and easy to follow. At my level it is crucial that it seems you make sure even a beginner can follow your tutorials. I think it allows for a lot more people to be introduced to flash programming and greensock platforms in particular and grants confidence on keeping at it.

As you can see I skipped some fundamentals and have a sporadic knowledge with gaping basic chasms. It seems to me I can do such cool things, I go further, and then get baffled on some basic stuff.

Some books I have tried are based on assumption that people come prepared with a certain level of skill and knowledge and then the book would wow with all the awesome code and techniques which is way above my level. So it is discouraging.

Since I have a luxury of you looking at my stuff and be familiar with my level I would like to ask you to recommend a book or few as I was not able to find a good one.

Link to comment
Share on other sites

as far as books go, I have read many and find that most of them get too complicated too quickly.

 

Coming from a strong AS2 background I found Rich Shupes book to be the most accessible http://www.amazon.com/Learning-ActionSc ... 144939017X

when making the switch to AS3.

 

 

 

This series that dives deep into many basic to advanced concepts is absolutely invaluable: http://active.tutsplus.com/sessions/as3-101/

 

Also this tutorial here: http://gamedev.michaeljameswilliams.com ... rial-base/ is probably the best "learn as you build" style tutorial that I have encountered.

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