Actionscript Receiving Mouse Events For Lower Indexed And Partially Covered Display Objects?

ぐ巨炮叔叔 提交于 2020-01-06 01:06:10

问题


i have 2 sprites on stage. bottomSprite is added to the display list first, followed by topSprite. topSprite partially covers bottomSprite.

i've added an event listener to bottomSprite for MouseEvent.MOUSE_MOVED notifications to simply trace the mouseX and mouseY coordinates. however, the notification doesn't work for the parts of bottomSprite that are covered by topSprite.

var bottomSprite:Sprite = new Sprite();
bottomSprite.graphics.beginFill(0x666666, 0.5);
bottomSprite.graphics.drawRect(150,150, 150, 150);
bottomSprite.graphics.endFill();
addChild(bottomSprite);

var topSprite:Sprite = new Sprite();
topSprite.graphics.beginFill(0x00FFFF, 0.5);
topSprite.graphics.drawRect(250,50, 150, 150);
topSprite.graphics.endFill();
addChild(topSprite);

bottomSprite.addEventListener(MouseEvent.MOUSE_MOVE, traceCoords);
function traceCoords(evt:MouseEvent):void
    {
    trace ("Coord = X:" + bottomSprite.mouseX + ", Y:" + bottomSprite.mouseY);
    }

回答1:


topSprite.mouseEnabled = false;

Note that the topSprite won't receive any more mouse events. You cannot make both of them receive mouse events simultaneously. Because mouse movement happens either on top of bottomSprite or topSprite, not both of them - they are siblings.

Had topSprite been a child of bottomSprite, later will receive mouse events when you hover across the former - because a child is part of its parent.



来源:https://stackoverflow.com/questions/2408486/actionscript-receiving-mouse-events-for-lower-indexed-and-partially-covered-disp

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