API Documentation for: 0.7.1
Show:

MouseEvent Class

Extends Event
Defined in: MouseEvent:40
Module: EaselJS

Passed as the parameter to all mouse/pointer/touch related events. For a listing of mouse events and their properties, see the DisplayObject and Stage event listings.

Constructor

MouseEvent

(
  • type
  • bubbles
  • cancelable
  • stageX
  • stageY
  • nativeEvent
  • pointerID
  • primary
  • rawX
  • rawY
)

Defined in MouseEvent:40

Parameters:

  • type String

    The event type.

  • bubbles Boolean

    Indicates whether the event will bubble through the display list.

  • cancelable Boolean

    Indicates whether the default behaviour of this event can be cancelled.

  • stageX Number

    The normalized x position relative to the stage.

  • stageY Number

    The normalized y position relative to the stage.

  • nativeEvent MouseEvent

    The native DOM event related to this mouse event.

  • pointerID Number

    The unique id for the pointer.

  • primary Boolean

    Indicates whether this is the primary pointer in a multitouch environment.

  • rawX Number

    The raw x position relative to the stage.

  • rawY Number

    The raw y position relative to the stage.

Methods

_dispatchEvent

(
  • eventObj
  • eventPhase
)
protected

Parameters:

addEventListener

(
  • type
  • listener
  • [useCapture]
)
Function | Object

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:

  • type String

    The string type of the event.

  • listener Function | Object

    An object with a handleEvent method, or a function that will be called when the event is dispatched.

  • [useCapture] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

Returns:

Function | Object:

Returns the listener for chaining or assignment.

clone

() MouseEvent

Inherited from Event but overwritten in clone:235

Returns a clone of the MouseEvent instance.

Returns:

MouseEvent:

a clone of the MouseEvent instance.

dispatchEvent

(
  • eventObj
  • [target]
)
Boolean

Dispatches the specified event to all listeners.

Example

 // Use a string event
 this.dispatchEvent("complete");

 // Use an Event instance
 var event = new createjs.Event("progress");
 this.dispatchEvent(event);

Parameters:

  • eventObj Object | String | Event

    An object with a "type" property, or a string type. While a generic object will work, it is recommended to use a CreateJS Event instance. If a string is used, dispatchEvent will construct an Event instance with the specified type.

  • [target] Object optional

    The object to use as the target property of the event object. This will default to the dispatching object. This parameter is deprecated and will be removed.

Returns:

Boolean:

Returns the value of eventObj.defaultPrevented.

hasEventListener

(
  • type
)
Boolean

Indicates whether there is at least one listener for the specified event type.

Parameters:

  • type String

    The string type of the event.

Returns:

Boolean:

Returns true if there is at least one listener for the specified event.

initialize

(
  • type
  • bubbles
  • cancelable
  • stageX
  • stageY
  • nativeEvent
  • pointerID
  • primary
  • rawX
  • rawY
)
protected

Inherited from EventDispatcher but overwritten in initialize:208

Initialization method.

Parameters:

  • type String

    The event type.

  • bubbles Boolean

    Indicates whether the event will bubble through the display list.

  • cancelable Boolean

    Indicates whether the default behaviour of this event can be cancelled.

  • stageX Number

    The normalized x position relative to the stage.

  • stageY Number

    The normalized y position relative to the stage.

  • nativeEvent MouseEvent

    The native DOM event related to this mouse event.

  • pointerID Number

    The unique id for the pointer.

  • primary Boolean

    Indicates whether this is the primary pointer in a multitouch environment.

  • rawX Number

    The raw x position relative to the stage.

  • rawY Number

    The raw y position relative to the stage.

off

(
  • type
  • listener
  • [useCapture]
)

Inherited from EventDispatcher: off:247

A shortcut to the removeEventListener method, with the same parameters and return value. This is a companion to the .on method.

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    The listener function or object.

  • [useCapture] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

on

(
  • type
  • listener
  • [scope]
  • [once=false]
  • [data]
  • [useCapture=false]
)
Function

Inherited from EventDispatcher: on:175

A shortcut method for using addEventListener that makes it easier to specify an execution scope, have a listener only run once, associate arbitrary data with the listener, and remove the listener.

This method works by creating an anonymous wrapper function and subscribing it with addEventListener. The created anonymous function is returned for use with .removeEventListener (or .off).

Example

    var listener = myBtn.on("click", handleClick, null, false, {count:3});
    function handleClick(evt, data) {
        data.count -= 1;
        console.log(this == myBtn); // true - scope defaults to the dispatcher
        if (data.count == 0) {
            alert("clicked 3 times!");
            myBtn.off("click", listener);
            // alternately: evt.remove();
        }
    }

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    An object with a handleEvent method, or a function that will be called when the event is dispatched.

  • [scope] Object optional

    The scope to execute the listener in. Defaults to the dispatcher/currentTarget for function listeners, and to the listener itself for object listeners (ie. using handleEvent).

  • [once=false] Boolean optional

    If true, the listener will remove itself after the first time it is triggered.

  • [data] optional

    Arbitrary data that will be included as the second parameter when the listener is called.

  • [useCapture=false] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

Returns:

Function:

Returns the anonymous function that was created and assigned as the listener. This is needed to remove the listener later using .removeEventListener.

preventDefault

()

Inherited from Event: preventDefault:193

Sets Event/defaultPrevented to true. Mirrors the DOM event standard.

remove

()

Inherited from Event: remove:221

Causes the active listener to be removed via removeEventListener();

    myBtn.addEventListener("click", function(evt) {
        // do stuff...
        evt.remove(); // removes this listener.
    });

removeAllEventListeners

(
  • [type]
)

Removes all listeners for the specified type, or all listeners of all types.

Example

 // Remove all listeners
 displayObject.removeAllEventListeners();

 // Remove all click listeners
 displayObject.removeAllEventListeners("click");

Parameters:

  • [type] String optional

    The string type of the event. If omitted, all listeners for all types will be removed.

removeEventListener

(
  • type
  • listener
  • [useCapture]
)

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

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    The listener function or object.

  • [useCapture] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

stopImmediatePropagation

()

Sets Event/propagationStopped and Event/immediatePropagationStopped to true. Mirrors the DOM event standard.

stopPropagation

()

Inherited from Event: stopPropagation:202

Sets Event/propagationStopped to true. Mirrors the DOM event standard.

toString

() String

Inherited from EventDispatcher but overwritten in toString:244

Returns a string representation of this object.

Returns:

String:

a string representation of the instance.

willTrigger

(
  • type
)
Boolean

Indicates whether there is at least one listener for the specified event type on this object or any of its ancestors (parent, parent's parent, etc). A return value of true indicates that if a bubbling event of the specified type is dispatched from this object, it will trigger at least one listener.

This is similar to hasEventListener, but it searches the entire event flow for a listener, not just this object.

Parameters:

  • type String

    The string type of the event.

Returns:

Boolean:

Returns true if there is at least one listener for the specified event.

Properties

_captureListeners

Object protected

_listeners

Object protected

bubbles

Boolean

Inherited from Event: bubbles:108

Indicates whether the event will bubble through the display list.

Default: false

cancelable

Boolean

Inherited from Event: cancelable:117

Indicates whether the default behaviour of this event can be cancelled via preventDefault. This is set via the Event constructor.

Default: false

currentTarget

Object

Inherited from Event: currentTarget:83

The current target that a bubbling event is being dispatched from. For non-bubbling events, this will always be the same as target. For example, if childObj.parent = parentObj, and a bubbling event is generated from childObj, then a listener on parentObj would receive the event with target=childObj (the original target) and currentTarget=parentObj (where the listener was added).

Default: null

defaultPrevented

Boolean

Inherited from Event: defaultPrevented:136

Indicates if preventDefault has been called on this event.

Default: false

Event_initialize

Function private

eventPhase

Number

Inherited from Event: eventPhase:95

For bubbling events, this indicates the current event phase:

  1. capture phase: starting from the top parent to the target
  2. at target phase: currently being dispatched from the target
  3. bubbling phase: from the target to the top parent

Default: 0

immediatePropagationStopped

Boolean

Indicates if stopImmediatePropagation has been called on this event.

Default: false

localX

Number

Defined in localX:173

Returns the x position of the mouse in the local coordinate system of the current target (ie. the dispatcher).

localY

Number

Defined in localY:183

Returns the y position of the mouse in the local coordinate system of the current target (ie. the dispatcher).

nativeEvent

HtmlMouseEvent

Defined in nativeEvent:119

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

Defined in onMouseMove:130

Deprecated: Use the DisplayObject "pressmove" event.

REMOVED. Use the DisplayObject pressmove event.

onMouseUp

Function deprecated

Defined in onMouseUp:137

Deprecated: Use the DisplayObject "pressup" event.

REMOVED. Use the DisplayObject pressup event.

pointerID

Number

Defined in pointerID:145

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

Defined in primary:153

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.

propagationStopped

Boolean

Inherited from Event: propagationStopped:146

Indicates if stopPropagation or stopImmediatePropagation has been called on this event.

Default: false

rawX

Number

Defined in rawX:103

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

Defined in rawY:111

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.

removed

Boolean

Inherited from Event: removed:166

Indicates if remove has been called on this event.

Default: false

stageX

Number

Defined in stageX:89

The normalized x position on the stage. This will always be within the range 0 to stage width.

stageY

Number

Defined in stageY:96

The normalized y position on the stage. This will always be within the range 0 to stage height.

target

Object

Inherited from Event: target:74

The object that generated an event.

Default: null

timeStamp

Number

Inherited from Event: timeStamp:127

The epoch time at which this event was created.

Default: 0

type

String

Inherited from Event: type:67

The type of event.

Events

mousemove

deprecated

Defined in mousemove:65

Deprecated: In favour of the DisplayObject "pressmove" event.

Available since 0.6.0

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 description for more information on mouse events.

mouseup

deprecated

Defined in mouseup:76

Deprecated: In favour of the DisplayObject "pressup" event.

Available since 0.6.0

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 description for more information on mouse events.