Jump to content
Search Community

Recommended Posts

friendlygiraffe
Posted

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);

Posted

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.

Posted

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?

friendlygiraffe
Posted

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);
}

Posted

If my post about your other question didn't help and you're still having trouble, feel free to post a very simple FLA that demonstrates the issue so that we can publish and see what's going on.

friendlygiraffe
Posted

Thanks for your response. I've narrowed it down to a problem in the child swf

 

If I use this.setChildIndex in the root of the child swf it doesn't remove

 

Still looking into it....

friendlygiraffe
Posted

Ok this is still not removing the SWFLoader contentDisplay:

 

private function loadSWF(num:Number)
    {
	    trace(mySWF);
	    if (mySWF)
	    {
		    swf_holder_mc.removeChild(mySWF);
		    trace(mySWF);
	    }
  mySWF = LoaderMax.getContent('swf' + num);
  swf_holder_mc.addChild(mySWF);

}

 

Any more ideas ?

friendlygiraffe
Posted (edited)

cannot upload attachement for some reason

Edited by friendlygiraffe
Posted

Try zipping it first and make sure it's not too big. If it is, just post it on your own web server somewhere and put the link here.

 

I really need to see your .FLA to know what's causing your problem.

friendlygiraffe
Posted

Sure here you go

 

clients.giantworks.co.uk/SWFload.zip

 

it's likely more a general AS3 question, but if you could help that'd be great

friendlygiraffe
Posted

Instead of tracing

 

 

[object ContentDisplay]
[object ContentDisplay]

 

it should say

 

 

null
[object ContentDisplay]

Posted

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?

friendlygiraffe
Posted

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

Posted

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 :(

friendlygiraffe
Posted

Hi thanks for your reply.

I'm not using a new loader every time. Just loading 7 swfs once from the XML and calling them using LoaderMax.getContent() and addChild()

 

I think I'll try removing all the internal events from the child swf before removeChild()

 

Thanks for your help

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