开发者

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

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.g开发者_高级运维raphics.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);
    }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜