Listen to click event on overlapped sprites

前提是你 提交于 2019-12-25 08:15:52

问题


I have two sprites in my movieclip, one under the other, and i want both to listen to mouse clicks event. I found that only the top level sprite receives the event when i click on it. I need to dispatch the events on both, so I can't use mouseenabled=false.

Is there a simple workaround for this?


回答1:


You can use the 'getObjectsUnderPoint' method native to the DisplayObjectContainer

You can see how it works here:

http://snipplr.com/view/34945/as3-trace-movieclips-under-mouse/

and the AS3 reference here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html

You would listen on the stage for any click event and if one occurs, check to see if the element you require is under that click position.




回答2:


Another solution is, that you listen to the click-event on the upper sprite, and fire it again with

dispatchEvent(new MousEvent(event));

Have a look at the "bubble" property of the event.



来源:https://stackoverflow.com/questions/4924558/listen-to-click-event-on-overlapped-sprites

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!