Skip to content
mikechambers edited this page Feb 7, 2011 · 1 revision

A MouseEvent instance is passed as the only parameter for all mouse event callbacks. It includes stageX and stageY properties, which indicate the cursor’s position relative to the stage coordinates. It also exposes onMouseMove & onMouseUp callbacks, which are only functional when the event object is passed to an onPress handler.

In the following example, “pressed” will be logged to the console when the mouse is pressed down over myShape, and thereafter “mouse moved” will be logged until the mouse is released whenever the mouse moves.

myShape.onPress = function(mouseEvent) {
  console.log("pressed");
  mouseEvent.onMouseMove = function(mouseEvent) { console.log("mouse moved: "+mouseEvent.stageX+","+mouseEvent.stageY); }
}

Mouse events

onPress

Called on DisplayObject. Called when the mouse is pressed down over the display object. When an onPress handler is called a MouseEvent object is passed as the only parameter which exposes onMouseMove & onMouseUp callbacks, which will be active until the mouse is released again. This allows you to develop interactions such as dragging within the scope of individual display objects, by adding handlers for mouse move and up when to the event passed to a onPress handler.

onClick

Called on DisplayObject. Called when the mouse is pressed down, then released over the same display object.

onMouseDown

Called on Stage. Called when the mouse is pressed down anywhere over the stage. This event is not broadcast for individual DisplayObjects.

onMouseUp

Called on Stage and MouseEvent (only instances passed to onPress handlers). Called when the mouse is released anywhere on the page. This event is not broadcast for individual DisplayObjects.

onMouseMove

Called on Stage and MouseEvent (only instances passed to onPress handlers). Called when the mouse moves anywhere on the stage. This event is not broadcast for individual DisplayObjects.

Where are MouseEvents broadcast?

Stage Only

  • onMouseDown
  • onMouseMove
  • onMouseUp

DisplayObjects (including Stage)

  • onPress
  • onClick