views:

273

answers:

1

I'm creating a simple drawing application that adds new Shape objects to a MovieClip "canvas" every time the user clicks and drags. The problem is, I'm noticing that even though the MouseEvent listeners are set to the MovieClip, the child Shape objects are being returned as targets as well. This disrupts the localX and localY as well, causing the drawing cursor to jump around as the coordinates change from being local to the entire MovieClip to local to the Shape the mouse is currently over.

Is there any way to retrieve the most parental target from a MouseEvent?

+1  A: 

you maybe simply wanna set DisplayObjectContainer::mouseChildren to false ... other than that, you can the currentTarget, which should be your MovieClip and use its DisplayObject::mouseX and DisplayObject::mouseY ... or you could use the MouseEvent::stageX and the MouseEvent::stageY and then DisplayObject::globalToLocal to transform it to your MovieClip's coordinate space ...

little sidenote: why MovieClip and not Sprite?

edit: the actual point, why i don't like using MovieClip is, that it's dynamic, so you get no compiler errors on typos ...

back2dos
The canvas does additional stuff that requires a movieclip. However, I may simply fact that out and use a sprite instead. All in all, one clip isn't going to hurt too much in terms of performance.
Soviut