Events of the Mouse Object


Events of the Mouse Object

The mouse is one of the most frequently used objects for interactive interfaces because the most common ways a user interacts with Flash are with either the mouse or the keyboard.

Table 14.3 shows the events for the Mouse object.

Table 14.3. Mouse Events

Event Handler Methods

Action Description

onMouseDown

This event occurs if the user presses the mouse button on the stage.

onMouseUp

This event occurs when the user releases the mouse button over the stage.

onMouseMove

This event occurs when the user moves the mouse over the stage.

onMouseWheel

This event occurs when the user uses the mouse wheel.


Now that you've seen all the events for the Mouse object, here is an example using the addListener() method and the onMouseWheel event.

Here is the code block used to detect the mouse wheel:

 //create the listener object var wheelListen:Object = new Object(); //create the event wheelListen.onMouseWheel = function(amount){    trace(amount); } //add the listener to the Mouse object Mouse.addListener(wheelListen); 

In this code block, we create a listener object. Then we create the event-handling method for listening to the mouse wheel. Notice that you pass the event-handling method a parameter. The amount parameter is a numerical value representing which direction the mouse wheel is spinning, and at what speed. We send this numerical value to the Output panel with the trace function. After that, we add the listener to the Mouse object.

Now when you test the movie, if the event doesn't fire when you spin the wheel, click the stage once to make sure it has focus. When the mouse wheel spins, you will see negative and positive numbers in the Output panel.

The other object that is most often used for user interaction is the Key object.




Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net