Search code examples
actionscript-3flash

Get click coordinate from the listener in AS3


I'm currently programing a little flash game and I've encountered some kind of a problem:

I have a sprite, let's call it gameBoard, which contains a background image and a lot of other small sprites. My problem is when gameboard put a click listener on itself, if I happened to click on one of the numerous sprites contained in the gameboard, the localX and localY are the one of the small sprite.

So, my question is:

How can I get the coordinate of my click relative to the event listener?


Solution

  • Pretty sure this is what you're asking.

    Trigger event from child to parent in AS3

    This is a fairly common question - you can use the event.currentTarget property instead of event.target to reference the object to which you added the event listener.

    To trigger the mouse event for the gameboard only:

    [gameboard_instance_name].mouseChildren = false;
    //[gameboard_instance_name].addEventListener(...);