0

I am creating a series of mini games and animations and plan on bringing them all into one flash file. Each of the games need to disappear when the player has finished them. I don't know what to put into the section in the external swfs when the game is done. I currently just have a trace ("finished").

In my main swf you should click start and a game swf appears and when you are finished it, it should disappear.

I have looked up tutorials and they something about accessing variables in the external swfs but I got nowhere with them.

1 Answers1

2

in place of trace("finished");, dispatch something like a complete event:

dispatchEvent(new Event(Event.COMPLETE));

Then listen for that event in the container swf and respond appropriately.

Here is an example for the host (parent) swf:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadDone, false,0,true);
loader.load(new URLRequest("temp2.swf"));

function loadDone(e:Event){
    trace("CONTENT LOADED");
    addChild(loader.content);
    loader.content.addEventListener(Event.COMPLETE,go,false,0,true); //listen on the capture phase (third parameter true) if you're complete event is NOT on the main timeline of your child swf
}

function go(e:Event):void {
    trace("Content is all done");
    removeChild(loader.content);
    loader.unloadAndStop(); //tries to free the app of all memory used by the loaded swf
    loader = null;
}

Another way, is in place of trace("finished"), you could have the child swf remove itself (as per a comment on the question). I would consider this a less desirable solution (though more encapsulated) as it lessens re usability and will likely still leave the swf in memory:

stop();
if(this.parent){
    this.parent.removeChild(this);
}
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40