Actionscript 3: Event.target returns children of movieclip

Problem:

You’ve added a listener to a movieclip, but the target returned is another movieclip or sprite within that movieclip.

Solution:

myMovieclip.mouseChildren = false;

Yeah, that’s all. Now the movieclip you added the listener to will be the only thing returned as the target of an event. If you want a little more proof before you go through all the trouble to add that line of code, then check my example below:

This movie requires Flash Player 9

Here’s the code (on the timeline):

blockLeft.addEventListener(MouseEvent.CLICK, clickBlock);
blockLeft.buttonMode = true;
blockLeft.mouseChildren = true;
 
blockRight.addEventListener(MouseEvent.CLICK, clickBlock);
blockRight.buttonMode = true;
blockRight.mouseChildren = false;
 
function clickBlock(e:Event):void
{
	txtTarget.text = "e.target.name: " + e.target.name;
}

Comments

One Response to “Actionscript 3: Event.target returns children of movieclip”

  1. Donna Whitaker on November 12th, 2008 8:33 pm

    nxger7a5244okey8

Leave a Reply