MouseEvent Class
This is passed as the parameter to mousedown, mouseup, mousemove, stagemouseup, stagemousedown, mouseover, mouseout and click events on DisplayObject instances.
Constructor
MouseEvent
-
type
-
stageX
-
stageY
-
target
-
nativeEvent
-
pointerID
-
primary
-
rawX
-
rawY
Parameters:
-
type
StringThe event type.
-
stageX
NumberThe normalized x position relative to the stage.
-
stageY
NumberThe normalized y position relative to the stage.
-
target
DisplayObjectThe display object this event relates to. Note that this will be overwritten when the event is dispatched via EventDispatcher.
-
nativeEvent
MouseEventThe native DOM event related to this mouse event.
-
pointerID
NumberThe unique id for the pointer.
-
primary
BooleanIndicates whether this is the primary pointer in a multitouch environment.
-
rawX
NumberThe raw x position relative to the stage.
-
rawY
NumberThe raw y position relative to the stage.
Item Index
Methods
Properties
- _listeners
- nativeEvent
- onMouseMove deprecated
- onMouseUp deprecated
- pointerID
- primary
- rawX
- rawY
- stageX
- stageY
- target
- type
Methods
addEventListener
-
type
-
listener
Adds the specified event listener. Note that adding multiple listeners to the same function will result in multiple callbacks getting fired.
Example
displayObject.addEventListener("click", handleClick);
function handleClick(event) {
// Click happened.
}
Parameters:
clone
()
MouseEvent
Returns a clone of the MouseEvent instance.
Returns:
dispatchEvent
-
eventObj
-
[target]
Dispatches the specified event to all listeners.
Example
// Use a string event
this.dispatchEvent("complete");
// Use an object
var event = {
type: "complete",
foo: "bar"
};
this.dispatchEvent(event);
Parameters:
-
eventObj
Object | StringAn object with a "type" property, or a string type. If a string is used, dispatchEvent will construct a generic event object with the specified type.
-
[target]
Object optionalThe object to use as the target property of the event object. This will default to the dispatching object.
Returns:
hasEventListener
-
type
Indicates whether there is at least one listener for the specified event type.
Parameters:
-
type
StringThe string type of the event.
Returns:
initialize
()
protected
Initialization method.
removeAllEventListeners
-
[type]
Removes all listeners for the specified type, or all listeners of all types.
Example
// Remove all listeners
displayObject.removeAllEvenListeners();
// Remove all click listeners
displayObject.removeAllEventListeners("click");
Parameters:
-
[type]
String optionalThe string type of the event. If omitted, all listeners for all types will be removed.
removeEventListener
-
type
-
listener
Removes the specified event listener.
Important Note: that you must pass the exact function reference used when the event was added. If a proxy function, or function closure is used as the callback, the proxy/closure reference must be used - a new proxy or closure will not work.
Example
displayObject.removeEventListener("click", handleClick);
Properties
nativeEvent
MouseEvent
The native MouseEvent generated by the browser. The properties and API for this event may differ between browsers. This property will be null if the EaselJS property was not directly generated from a native MouseEvent.
Default: null
onMouseMove
Function
deprecated
For events of type "onPress" only you can assign a handler to the onMouseMove property. This handler will be called every time the mouse is moved until the mouse is released. This is useful for operations such as drag and drop.
onMouseUp
Function
deprecated
For events of type "onPress" only you can assign a handler to the onMouseUp property. This handler will be called every time the mouse is moved until the mouse is released. This is useful for operations such as drag and drop.
pointerID
Number
The unique id for the pointer (touch point or cursor). This will be either -1 for the mouse, or the system supplied id value.
primary
Boolean
Indicates whether this is the primary pointer in a multitouch environment. This will always be true for the mouse. For touch pointers, the first pointer in the current stack will be considered the primary pointer.
rawX
Number
The raw x position relative to the stage. Normally this will be the same as the stageX value, unless stage.mouseMoveOutside is true and the pointer is outside of the stage bounds.
rawY
Number
The raw y position relative to the stage. Normally this will be the same as the stageY value, unless stage.mouseMoveOutside is true and the pointer is outside of the stage bounds.
stageX
Number
The normalized x position on the stage. This will always be within the range 0 to stage width.
stageY
Number
The normalized y position on the stage. This will always be within the range 0 to stage height.
type
String
The type of mouse event. This will be the same as the handler it maps to (onPress, onMouseDown, onMouseUp, onMouseMove, or onClick).
Events
mousemove
For MouseEvent objects of type "mousedown", mousemove events will be dispatched from the event object until the user releases the mouse anywhere. This enables you to listen to mouse move interactions for the duration of a press, which can be very useful for operations such as drag and drop. See the MouseEvent class for a listing of event properties.
mouseup
For MouseEvent objects of type "mousedown", a mouseup event will be dispatched from the event object when the user releases the mouse anywhere. This enables you to listen for a corresponding mouse up from a specific press, which can be very useful for operations such as drag and drop. See the MouseEvent class for a listing of event properties.