Skip to main content
March 15, 2010
Question

Closing SWF window

  • March 15, 2010
  • 3 replies
  • 930 views

Hey

I have been searching the web for hours trying to find the right code  for AS3. So I'm hoping you can help me to get the right piece of code.

So I have a background element which I press button and it loads an swf  on top of the original swf. The one which loads is a child and I have an  'X' button which I want to close and I have no idea what the code is.  Once the 'X' button is on say a mouse down it closes the swf and you can  still see the original which is below it.

I hope I have explained it so you can understand me

Thanks for the help.

This topic has been closed for replies.

3 replies

March 22, 2010

Thanks for all of the suggestions guys but I still can't get the little bugger to close lol!!!

I've tried:

if(btnClose.hasEventListener(MouseEvent.CLICK) == false)
btnClose.addEventListener(MouseEvent.CLICK , removeMe);

function removeMe(evt:MouseEvent):void
{   
    if(this.parent) return;

    btnClose.removeEventListener(MouseEvent.CLICK , removeMe);

    if(this.parent is Loader)
    {
        this.parent.parent.removeChild(this.parent);
        Loader(this.parent).unloadAndStop();       
    }
    else
    {
        this.parent.removeChild(this);
    }
}


Along with what else has been suggested above ... any more ideas would be helpful but it's no major biggy if I don't get this working coz I've then got something to write about in my evaluation.

Thanks again for all your patience & kind words so far!!!!!!!!!!!!!

Ned Murphy
Legend
March 22, 2010

That code doesn't resemble anything you've been offered here. Based on your usage of parent references  what you just showed indicates you're telling a different story elsewhere.  Where is btnClose?  Is it on the same timeline as btnEar or is it buried inside the swf that was loaded?

The only problem wiuth the code I offered is that the unload command shouldn't have an argument, but that assumes the buttons areboth at the same level.

Participating Frequently
March 15, 2010

An swf's stage extends MovieClip, right? If so, you could set secondary_swf.visible to false. This wouldn't actually close it, so it would still take up memory, but at least it would make the main page visible again.

Ned Murphy
Legend
March 15, 2010

It isn't really clear to me what you are describing.  Can you show the code you are using and describe what elements of that code involve what you are trying to remove?

March 15, 2010

I've basically got a website that loads an external swf file by  clicking on a button.  This swf file is then loaded in the frame & I  would like to be able to close it again so that the main web page can  be seen again.

My code is as follows:

btnEar.addEventListener(MouseEvent.CLICK,CLICK);

function  CLICK   {      var ldr:Loader=new Loader()

var urlR:URLRequest=new URLRequest("HearingAid.swf");

ldr.load(urlR);

addChild(ldr);

ldr.x=20;

ldr.y=100;     }

Ned Murphy
Legend
March 15, 2010

If you move the loader declaration outside of the function it can be used by other functions...  I recommend against naming your function the same as the event constant (CLICK)

btnEar.addEventListener(MouseEvent.CLICK, loadCLICK);

var ldr:Loader;

function  loadCLICK(evt:MouseEvent):void   {    

     ldr = new Loader();

     var urlR:URLRequest=new URLRequest("HearingAid.swf");

     ldr.load(urlR);

     addChild(ldr);

     ldr.x=20;

     ldr.y=100;   

}

btnX.addEventListener(MouseEvent.CLICK, unloadCLICK);

function  unloadCLICK(evt:MouseEvent):void   {    

     ldr.unload(urlR);

     removeChild(ldr);  

}