Areas Behind Display Objects and Mouse Events in Flash CS3

If you assign a mouse event listener to a display object, then portions of the object that are behind another interactive display object will not respond to the events. That is because AS3 notifies about a mouse event only the front-most object.

Our movie contains static text, several dynamic text boxes created at autoring time (globalCoords, localCoords, numClicks), and two Sprites created programmatically. These Sprites, spBoard and spDisk are children of the MainTimeline. spDisk is added second, so it is in front of spBoard.

As you can see from the source code below, we add to the Stage the listener that listens to MouseEvent.MOUSE_MOVE and displays global coordinates of the mouse pointer with respect to the Stage and local coordinates with respect to spBoard. We add a listener to spBoard that listens to MouseEvent.CLICK. The listener counts the number of clicks and displays that number in numClicks box.

We notice that when the area of spDisk is clicked, the click is not registered. This is because AS3 notifies of the event only the front-most InteractiveObject; that is, spDisk. spBoard is not notified. To combat this often undesirable effect, we use spDisk.mouseEnabled=false setting.


var spBoard:Sprite = new Sprite();,0x333333);;,0,200,200);;


var spDisk:Sprite = new Sprite();,0x000000);;,0,40);;



spBoard.x = 50;

spBoard.y = 65;



spDisk.x = 120;

spDisk.y = 120;


var clicksCounter:Number=0;





function stageMove(evt:MouseEvent):void {


globalCoords.text="( "+String(Math.round(mouseX*100)/100)+

" , "+String(Math.round(mouseY*100)/100)+" )";


localCoords.text="( "+String(Math.round(spBoard.mouseX*100)/100)+

" , "+String(Math.round(spBoard.mouseY*100)/100)+" )";






function boardClicked(evt:MouseEvent):void {







function disableClicked(evt:MouseEvent):void {






function resetClicked(evt:MouseEvent):void {







The fla file linked below contains complete, commented source code for the Flash movie above.

Back to Intermediate Tutorials              Back to Flash and Math Home

We welcome your comments, suggestions, and contributions. Click the Contact Us link below and email one of us.

Adobe®, Flash®, ActionScript®, Flex® are registered trademarks of Adobe Systems Incorporated.