FORUMS: list search recent posts

AS3: Closing a movie clip with a mouse click?

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ben Mettler
AS3: Closing a movie clip with a mouse click?
on May 8, 2012 at 8:29:38 pm

I have a button that loads a movie clip and I want to be able to close that same movieclip by clicking anywhere.

This is my code so far:

btn_2.addEventListener(MouseEvent.CLICK, goBio);
function goBio (e:MouseEvent):void {
var newBio:BioToc = new BioToc();
this.addChild(newBio);
newBio.x = 25;
newBio.y = 45;
}


Return to posts index

Pieter Helsen
Re: AS3: Closing a movie clip with a mouse click?
on May 9, 2012 at 8:18:12 am

Hi Ben,

The easiest way to do that is by creating an invisible movie on top of the entire swf...

This code should do the trick (I wrote this without the help of my editor, so it might contain some syntax errors :)):


var newBio:BioToc;
var invisMC:MovieClip;

btn_2.addEventListener(MouseEvent.CLICK, goBio);

function goBio (e:MouseEvent):void {
newBio = new BioToc();
this.addChild(newBio);
newBio.x = 25;
newBio.y = 45;

invisMC = new MovieClip();
invisMC.graphics.clear();
invisMC.graphics.beginFill(0xFF0000, 0); // will fill the movieclip with a red color
invisMC.graphics.drawRectangle(0, 0, stage.stageWidth, stage.stageHeight);
invisMC.graphics.endFill();
invisMC.addEventListener(MouseEvent.CLICK, closeHandler, false, 0, true);
this.addChild(invisMC);
}

function closeHandler(e:MouseEvent):void {
this.removeChild(newBio);
this.removeChild(invisMC);
newBio = null;
invisMC = null;
}


Kind regards,
Pieter

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]