Jump to content
Search Community

Cannot remove Loaded SWF

friendlygiraffe test
Moderator Tag

Recommended Posts

Hi I cannot seem to be able to remove a loaded SWF using removeChild(). Here is my code

 

XML:

<SWFLoader name="swf1" url="swfs/start.swf" load="true">

 

AS:

var currentPage:SWFLoader;
if (currentPage != null)
{
swf_holder_mc.removeChild(currentPage.content);
}
currentPage = LoaderMax.getLoader('swf1');
swf_holder_mc.addChild(currentPage.content);

Link to comment
Share on other sites

Hello

 

I'm pretty sure you have to use the load() and unload() calls as well as the add/remove content lines. Someone correct me if I'm wrong but I think your code should look like this:

 

var currentPage:SWFLoader;
if (currentPage != null)
{
swf_holder_mc.removeChild(currentPage.content);
currentPage.unload();
}
currentPage = LoaderMax.getLoader('swf1');
currentPage.load(true);
swf_holder_mc.addChild(currentPage.content);

 

Anyway, it's something for you to try if you haven't done so already.

Link to comment
Share on other sites

Thanks for chiming in, Amnesicat. Yeah, load() and unload() are the important ones if you truly want to load and unload the actual content. It looks like maybe you were just trying to remove the ContentDisplay from the display list. One problem I saw right away with your code is that you declare your currentPage variable right before you run the if() statement. Since you're declaring that variable right above and you don't populate that variable, it'll always be null. So that if() statement will always evaluate as false, hence your removeChild() never gets called.

 

I'm not sure what you're doing elsewhere in your code, but I'm guessing you meant to declare that variable as a class-level property or something?

Link to comment
Share on other sites

Thanks for your replies. I have declared var currentPage:SWFLoader; in the doc class now.

 

Yes, I am just trying to remove the ContentDisplay from the display list, I don't want to unload it. I'm still not getting there though. Here is my code

 

if (currentPage != null)
  {
trace('before',num,currentPage);
swf_holder_mc.removeChild(currentPage.content);
currentPage.unload();
trace('after',num,currentPage);
  }
  currentPage = LoaderMax.getLoader('swf1');
  currentPage.load(true);
  swf_holder_mc.addChild(currentPage.content);
}

Link to comment
Share on other sites

Oh, it looks like you're expecting that if you remove a DisplayObject from the display list, that it will make any references to that DisplayObject null (in this case "mySWF") but that's not correct. A DisplayObject still exists even if you haven't placed it into the display list. So, for example:

 

 

var mySprite:Sprite = new Sprite();
myContainer.addChild(mySprite); //adds it to the display list
myContainer.removeChild(mySprite); //removes it from the display list
trace(mySprite); //still traces [sprite] - this is NOT null.

 

So in your example file, I can't find anything that's broken. Am I missing something?

Link to comment
Share on other sites

Oh I see.

 

Well I have a container swf that's loading a few child swfs. The only problem is after skipping through it loads of times it becomes slow

 

Perhaps I'm looking at this the wrong way. Would it be better to unload? dispose? I don't know much about garbage collection

 

Thanks for your help

Link to comment
Share on other sites

It shouldn't cause problems if you're just doing an addChild() and removeChild() to the same assets - it's not like putting it into the display list and pulling it out makes everything slow down over time. It should be fine. However, if you are creating a new loader each time and loading the same asset(s) multiple times without ever disposing of the old one(s), that would explain the slowdown. There are a LOT of potential reasons for gc problems and it would be difficult for me to list them all here or guess at what is causing the issue in your file particularly. I wish I had a simple answer to give you that'd solve your problem for sure :(

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