Flash Lite 2.x and 3.0 ActionScript Language Reference

onMouseMove (Mouse.onMouseMove event listener)

onMouseMove = function() {}

Notified when the mouse moves. To use the onMouseMove listener, you must create a listener object. You can then define a function for onMouseMove and use addListener() to register the listener with the Mouse object, as shown in the following code:

var someListener:Object = new Object();
someListener.onMouseMove = function () { ... };
Mouse.addListener(someListener);

Listeners enable different pieces of code to cooperate because multiple listeners can receive notification about a single event.

Note: This event listener is supported in Flash Lite only if System.capabilities.hasMouse is true.

Example

The following example uses the mouse pointer as a tool to draw lines using onMouseMove and the Drawing API. The user draws a line by moving the pointer.

this.createEmptyMovieClip("canvas_mc", this.getNextHighestDepth());
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
    this.isDrawing = true;
    canvas_mc.lineStyle(2, 0xFF0000, 100);
    canvas_mc.moveTo(_xmouse, _ymouse);
};
mouseListener.onMouseMove = function() {
    if (this.isDrawing) {
        canvas_mc.lineTo(_xmouse, _ymouse);
    }
    updateAfterEvent();
};
mouseListener.onMouseUp = function() {
    this.isDrawing = false;
};
Mouse.addListener(mouseListener);

The following example sets the x and y positions of the pointer_mc movie clip instance to the x and y pointer positions. The device must support a stylus or mouse for this example to work. To use the example, you create a movie clip and set its Linkage identifier to pointer_id. Then add the following ActionScript code to Frame 1 of the Timeline:

this.attachMovie("pointer_id", "pointer_mc", this.getNextHighestDepth());
var mouseListener:Object = new Object();
mouseListener.onMouseMove = function() {
    pointer_mc._x = _xmouse;
    pointer_mc._y = _ymouse;
};
Mouse.addListener(mouseListener);

See also

addListener (Mouse.addListener method)