Skip to main content
Participant
April 17, 2015
Question

close an external swf which is part of an array

  • April 17, 2015
  • 1 reply
  • 250 views

Hi.

Noob and having to learn all this pretty quick.. So thanks for any help you can give me.

Here's the basics - Flash cs4 and as3.

I'm making an app which is, at the moment, a game.

I have an animation on the maintimeline - this (at the momoent - until I make it functional) animates through the menu selection to the games menu.. All fine.

I then have placed an empty MC on the stage which will contain all the games. So I click the first game - Flash then selects from 5 possible versions (3 in the code at the mo) and it plays on top of the menu - with a master menu at the bottom of the page.

The game loads fine, the random loading works fine - I just can't get rid of the imported SWF.  I've tried a multitude of ways and codes from the internet - had to give up in the end yesterday and so am starting with fresh hope today

I think, the ideal scenario, for me, is to have each SWF that imports - to switch itself off at the end of the game - last frame and disappear. I know it is possible - I'm pretty sure, back in the day in AS2, it was as simple as close.this (or something like that)

thanks

    stop();

    bee.addEventListener(MouseEvent.CLICK, Click);

function Click( event:MouseEvent):void {

    gotoAndPlay(currentFrame+1);

}

bee.addEventListener(MouseEvent.CLICK,f);

function f(e:Event):void{

var movieArray:Array = ["howmanybees1", "howmanybees2", "howmanybees3",];

var loader:Loader = new Loader();

var index:int = movieArray.length * Math.random();

var url:String = movieArray[index] + '.swf';

trace("Attempting to load", url);

loader.load(new URLRequest(url));    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderComplete);

loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderIOError);

addChild(loader);

function loaderComplete(e:Event):void {    

    trace("Successfully loaded", url);

    } function loaderIOError(e:IOErrorEvent):void {    

    trace("Failed to load", url);   

    }

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
April 17, 2015

Look into using the Loader.unload() method.   Normally what you would do for a loaded swf is to have the swf dispatch a custom event for which the main file assigns an event listener after the swf has finished loading.  When the loaded swf dispatches that event the main file catches it and unloads the loaded file.

Participant
April 17, 2015

Thanks Ned.

I have tried - which essentially means - I've been stalking forums - copying code and trying to shoehorn it in to my game.. I guess my real problem not understanding code enough yet to be able to use it with my set up.

I've tried to dispatch an event from the ext swf on the last frame and have the main swf hear the call - but I can't get it to work - most likely because I am putting the code in the wrong place??

Ned Murphy
Legend
April 17, 2015

Show the code you are trying to use.  It helps locate a problem and/or shows what you tried if you do.