Events of the Mouse ObjectThe 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.
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. |