Flash Lite 2.x and 3.0 ActionScript Language Reference

onMouseDown (Mouse.onMouseDown event listener)

onMouseDown = function() {}

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

var someListener:Object = new Object();
someListener.onMouseDown = 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 or System.capabilities.hasStylus is true.

Example

The following example uses the Drawing API to draw a rectangle when the user presses the mouse button, moves the mouse, and then releases the mouse button at runtime.

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

See also

addListener (Mouse.addListener method)