Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

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.

Please read Learning ActionScript Function and Understand ActionScript Event before starting this Mouse Events tutorial series.

Mouse-Input Events

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.

Mouse-input mouse move event

The following diagram illustrate that when the left button of mouse is pressed down, it will trigger the MOUSE_DOWN mouse event.

Mouse-input mouse down event

There are many types of mouse events. The most commonly used mouse events are:

  • MouseEvent.MOUSE_CLICK
    When primary mouse button is pressed down is released
  • MouseEvent.MOUSE_DOWN
    When primary mouse button is pressed down
  • MouseEvent.MOUSE_UP
    When primary mouse button is released
  • MouseEvent.MOUSE_MOVE
    When mouse is moving within the Flash Movie area.
  • MouseEvent.MOUSE_OVER
    When mouse is moving over display objects (e.g. text field, button, etc...)
  • MouseEvent.MOUSE_OUT
    When mouse leave display objects.

How to Register EventListener for Mouse Event

Here's the procedures to register an EventListener for mouse event.

  1. Decide the Mouse-Input types (e.g. MOUSE_CLICK, MOUSE_DOWN, etc...) you wish to listen.
  2. Write a function for the Listener function with single MouseEvent parameter. This function will be called when the desire Mouse-Input events happen.
  3. 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.

ActionScript function syntax

In this example, when a visitor click on the Red Button (redButton), the function (listenMouseEvent) will be called.

flash actionscript tutorial, flash animation tutorial