Mouse Wheel Support in Flash Player 7

By: Mustafa Basgun

Page 1 of 1

Set for printing

Starting with version 7, Flash Player now offers mouse wheel support on the Windows platform. In this tutorial, we will explore two new features: the onMouseWheel listener, and the TextField.mouseWheelEnabled property. In the first two examples, we'll use onMouseWheel to control the horizontal and vertical movement of a movie clip. In the last example, we'll enable/disable mouse wheel support in a Flash text field using the mouseWheelEnabled property.

The onMouseWheel Listener

The Mouse.onMouseWheel object is a listener that is notified when the user rolls the mouse wheel. This enables the Flash author to assign custom actions to mouse wheel events. In the Flash movie below, for example, the mouse wheel controls the horizontal movement of the mcForMouseWheel movie clip. To do this, we create a listener object (mouseListener), define the onMouseWheel function, and register it using the Mouse.addListener() method.

NOTE: You must bring focus to the Flash movie by clicking inside it before scrolling your mouse wheel. Additionally, please keep in mind that you must have the latest Flash Player in order to view the movies correctly, and it doesn't work in Opera. To see what version of Flash is installed on NN and Mozilla, choose Help > About Plug-ins, and look for Shockwave Flash.

In this example, the x coordinate of the mcForMouseWheel movie clip instance (the red box) is altered each time we roll the mouse wheel (see Figure 1).

Mouse wheel support for x coordinate
Figure 1  Changing a movie clip's x coordinate with a mouse wheel

We can use the same logic to control the mcForMouseWheel movie clip's y coordinate:

The code, as you might have guessed, looks like this:

Mouse wheel support for y coordinate
Figure 2   Changing a movie clip's y coordinate with a mouse wheel

NOTE: The number indicating how many lines should be scrolled for each notch is a system-level regulation. So, it can be modified by the user via Windows settings.

The mouseWheelEnabled Property

The mouseWheelEnabled property enables/disables mouse wheel scrolling in multiline Flash text fields. TextField.mouseWheelEnabled is a Boolean value that indicates whether Flash Player should automatically scroll a text field when the user rolls the mouse wheel. This property is true by default.

The following code was used to create the sample above:

Mouse wheel support for dynamic text fields
Figure 3   Enabling/disabling mouse wheel support

This mouseWheelEnabled property is useful when you want to prevent mouse wheel scrolling of text fields, or implement your own text field scrolling.

Approximate download size: 255k


Page 1 of 1 1

Download Support Files

Mouse.onMouseWheel, TextField.mouseWheelEnabled, Flash MX 2004, Flash Player 7