/ Published in: ActionScript 3
Will trace the name of the display object that is actually receiving mouse events. Useful when the target of your mouse event is not what you are expecting. Oh, the fix 80% of the time is mouseChildren = false;
Expand |
Embed | Plain Text
addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void{trace(e.target+" : "+e.target.name);});
Comments
Subscribe to comments
You need to login to post a comment.

For when you really get confused, here's how to apply that to every clickable object in your movie
makeEverythingIDselfOnClick(this);function IDselfOnClick(e:MouseEvent):void { trace("you clicked on ["+e.currentTarget+"] "+e.currentTarget.name); }
function makeEverythingIDselfOnClick(target:DisplayObjectContainer):void { trace("target = " + target.name) for(var i:int=0; i
aw, c'mon - no code in comments? seriously?
makeEverythingIDselfOnClick(this); function IDselfOnClick(e:MouseEvent):void { trace("you clicked on ["+e.currentTarget+"] "+e.currentTarget.name); } function makeEverythingIDselfOnClick(target:DisplayObjectContainer):void { trace("target = " + target.name) for(var i:int=0; i<target.numChildren; i++) { var child = target.getChildAt(i); if( (child is InteractiveObject) ) { InteractiveObject(child).addEventListener(MouseEvent.CLICK,IDselfOnClick, false, 0, true); } if( (child is DisplayObjectContainer)&&(child != target) ) { makeEverythingIDselfOnClick(child); } } }there we go!
also keep in mind that if you have a MovieClip (or similar) and you want all InteractiveObject children accepting clicks, you could use one single listener on the container object and use "target" to catch the children. But beware of the DisplayObjects that aren't InteractiveObjects (like Shapes) - they will not be refered to when clicking, thus "target" will refer to the container InteractiveObject - unless the "useCapture" in the listener is set to "true" - then it will not respond on clicks on non-InteractiveObjects.
obj.addEventListener(MouseEvent.CLICK, objClick, false);
function objClick(e:MouseEvent):void { trace("ct:", e.currentTarget.name); // traces: obj's name trace(e.target.name); //traces: nested objects name }
(oh, i guess I'm just elaborating on thing already posted)