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

Posted by Chunk1978 on Stack Overflow See other posts from Stack Overflow or by Chunk1978
Published on 2010-03-09T11:03:19Z Indexed on 2010/03/09 11:06 UTC
Read the original article Hit count: 242

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);
    }

© Stack Overflow or respective owner

Related posts about actionscript

Related posts about displaylist