Flash ActionScript 3 Mouse Events Tutorials
The most common user interaction with Flash Movies should be the mouse and keybaord. In this Flash ActionScript tutorial, we will discuss how to use mouse to interact with Flash Movie.
Whenever a user use the mouse, the mouse will trigger mouse-input event. The most common mouse motion that trigger mouse-input events are:
- Click and release left mouse button.
- Moving the mouse.
The following diagram illustrate that when a mouse is moving, it will trigger the MOUSE_MOVE mouse event.
The following diagram illustrate that when the left button of mouse is pressed down, it will trigger the MOUSE_DOWN mouse event.
There are many types of mouse events. The most commonly used mouse events are:
When primary mouse button is pressed down is released
When primary mouse button is pressed down
When primary mouse button is released
When mouse is moving within the Flash Movie area.
When mouse is moving over display objects (e.g. text field, button, etc...)
When mouse leave display objects.
How to Register EventListener for Mouse Event
Here's the procedures to register an EventListener for mouse event.
- Decide the Mouse-Input types (e.g. MOUSE_CLICK, MOUSE_DOWN, etc...) you wish to listen.
- Write a function for the Listener function with single MouseEvent parameter. This function will be called when the desire Mouse-Input events happen.
- Register or hook up the function with the object (e.g. button, textfield, etc...) that is given instruction to listen to the mouse-input event.
The following diagram illustrate how to register an EventListener for a Mouse Event.
In this example, when a visitor click on the Red Button (redButton), the function (listenMouseEvent) will be called.