Skip to main content
Participant
March 8, 2010
Question

unloading an external swf from itself

  • March 8, 2010
  • 1 reply
  • 350 views

Hello there,

I have a really simple problem regarding the unloading of swf's. I've searched for solutions but somehow I am having some difficulties understanding all the parent-child associations.

So, I have main swf that has four buttons, each loading an external swf. The buttons are on the main timeline. The swf's that are loaded have a return button on their main timelines that would need to unload the current swf and thus return to my main swf.

If some good samaritan could explain to me exactly what kind of code I would need to put into my return-buttons to make this thing work?

This topic has been closed for replies.

1 reply

March 8, 2010

There are a couple ways you can do it, including using parent to simply call a function in the main timeline. I'd probably use an event though - have your main swf, the one doing the loading, listen for a custom remove event on the loaded swf's and removeChild on them. So, in your return buttons you coud do:

function returnClicked(e:MouseEvent = null):void

{

     parent.parent.removeCurrentSwf();

     dispatchEvent(new event("removeLoadedContent"));
}

So, either line 1 or 2... not both.

Line 1 is a bit more fragile, if you change your content around it could stop working because it relies on the hierarchy. The event method is better - you just then also have to add the listener when you load in your movies:

var myLoader:Loader = new Loader();
myLoader.load(new URLRequest("b2.swf"));
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, addRemoveListener, false, 0, true);
addChild(myLoader);

function addRemoveListener(e:Event):void
{

     myLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, addRemoveListener);
    e.target.content.addEventListener("removeLoadedContent", removeCurrentSWF, false, 0, true);
}

function removeCurrentSWF(e:Event):void
{
    trace("got it");
}