AS3 If Statement: Turn a movie clip on/off with one button

Create a button component on your stage.
Give it an instance name of bSwitch.

Create a movieClip on your stage.
Give it an instance name of mcBulb.

Actionscript:

bSwitch.addEventListener(MouseEvent.CLICK, fSwitch);

bSwitch.label=" Turn On" ;
mcBulb.visible=false;
mcBulb.mouseEnabled=false;

function fSwitch(event:MouseEvent):void {
if (bSwitch.label==" Turn On" ){
bSwitch.label=" Turn Off" ;
mcBulb.visible=true;

}else if(bSwitch.label==" Turn Off" ){
bSwitch.label=" Turn On" ;
mcBulb.visible=false;

}

}

Example:

Get Adobe Flash player

One Response to “AS3 If Statement: Turn a movie clip on/off with one button”

  • dkroth says:

    Wanted to say thanks for the code sample. Incredibly easy to implement – major time saver. Thanks for your efforts!
    D Kroth
    Multimedia Designer
    Ortho-McNeil Pharma Inc

Leave a Reply