Listen to click event on overlapped sprites

2019-08-16 23:12发布

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?

2条回答
萌系小妹纸
2楼-- · 2019-08-16 23:37

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.

查看更多
Luminary・发光体
3楼-- · 2019-08-16 23:50

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.

查看更多
登录 后发表回答