Actionscript Receiving Mouse Events For Lower Indexed And Partially Covered Display Objects?
- by Chunk1978
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);
}