Skip to main content
Participant
June 11, 2012
Question

Button inside a mc to unload itself

  • June 11, 2012
  • 1 reply
  • 608 views

Hi everyone,

The title is pretty self explanatory. I know this subject I've been previously covered but it still unclear with the code I'm using. Please help.

This is the code I put on the main movie clip to load it:

var request:URLRequest = new URLRequest("externalMC.swf");
var loader:Loader = new Loader();

loader.load(request);
addChild(loader);

and this is the code inside the externalMC that contains a button called closeButt

       closeButt.addEventListener(MouseEvent.CLICK,closeT );

function closeT(e:Event):void{
this.parent.removeChild(this);

}

I'm doing something wrong obviously but I know I'm not far from the answer, just can't get it...

Thanks

This topic has been closed for replies.

1 reply

esdebon
Inspiring
June 11, 2012

MovieClip(parent.parent).removeChild(this);

Participant
June 11, 2012

Hi esdebon,

with this code:

closeButt.addEventListener(MouseEvent.CLICK,closeT ); 

function closeT(e:Event):void{
MovieClip(parent.parent).removeChild(this);

}

that gave me this error:

Error #2025: The supplied DisplayObject must be a child of the caller

at flash.display::DisplayObjectContainer/removeChild()

at externalMC_fla::MainTimeline/closeT()

:S

esdebon
Inspiring
June 11, 2012

MovieClip(parent.parent.parent).removeChild(this);

or

MovieClip(root).removeChild(this);