Feb 9

Problems using the MovieClip’s “enabled” property - AS3

Category: AS3

UPDATED: This is a more in depth look at mouseEnabled and mouseChildren.

I’ve racked my brain and scoured the internet for 2 days now wondering why I’m having so much trouble getting the enabled property of a MovieClip to work correctly. It should be as easy as saying:

mcClip.enabled = false;

All Button functionality should be disabled right?! Not so in AS3 my friend. The situation goes awry when using event listeners. But the thing is that AS3 is completely event based, so I’m not even sure what use the enabled property is, but that could be my bias. Here is what was really going on. Instead of using enabled = false, you need to use mouseEnabled = false. But here is the kicker: if you have any MovieClips inside of the MovieClip that you are applying events to (regardless if there are instance named or not), that container MovieClip will continue to receive events (CLICK, ROLL_OVER, etc). You need to use mouseChildren = false on that container clip, and THEN the disable/enable toggle will work. Place the following code on the timeline with aMovieClip containing another MovieClip inside it on stage.

// Importsimport flash.events.MouseEvent

// MovieClip on the timeline with other MovieClip inside

this.mcContainer.buttonMode = true ;

this.mcContainer.mouseChildren = false ;

this.mcContainer.addEventListener(MouseEvent.CLICK, this.run)

// Event handler

function run ($event:MouseEvent) {

trace(”RUN”)

}

// Toggle enabling

function manageButtonState ($clip:MovieClip, $state:String = “ON”):void {

switch ($state.toUpperCase()) {

case “ON” :

$clip.mouseEnabled= true;

break;

case “OFF” :

$clip.mouseEnabled = false;

break;

default :

$clip.mouseEnabled= true;

}

}

// Call toggle

this.manageButtonState (this.mcContainer, “OFF”);

Download Example

No Comments

Leave a comment