View comments | RSS feed

on handler

on(mouseEvent:Object) {
// your statements here
}

Specifies the mouse event or keypress that triggers an action.

Availability: ActionScript 1.0; Flash Player 2 - Flash 2. Not all events are supported in Flash 2.

Parameters

mouseEvent:Object - A mouseEvent is a trigger called an event . When the event occurs, the statements following it within curly braces ({ }) execute. Any of the following values can be specified for the mouseEvent parameter:

For a list of key constants, see the Key class.

Example

In the following script, the startDrag() function executes when the mouse is pressed, and the conditional script is executed when the mouse is released and the object is dropped:

on (press) {
 startDrag(this);
}
on (release) {
 trace("X:"+this._x);
 trace("Y:"+this._y);
 stopDrag();
}

See also

onClipEvent handler, Key


Version 8

Comments


Fumio Nonaka said on Dec 29, 2005 at 6:07 PM :
"For a list of key constants, see the Key class."

Key constants of the 'on (keyPress)' handler are different from key codes,
which the Key class's constants property returns. You should specify a
key constant shown in the code hinting or the character which you would
like to inspect.

The following statement yields syntax error:

on (keyPress Key.SPACE) {}

To inspect "a":
// on (keyPress 65) {} // syntax error
on (keyPress "a") {}

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001752.html