94
Chapter 5: Creating Interaction with ActionScript
Creating interactivity and visual effects
To create interactivity and other visual effects, you need to understand the following techniques:
•
Creating a custom mouse pointer
•
Getting the mouse position
•
Capturing keypresses
•
Setting color values
•
Creating sound controls
•
Detecting collisions
•
Creating a simple line drawing tool
Creating a custom mouse pointer
A standard mouse pointer is the operating system’s onscreen representation of the position of the
user’s mouse. By replacing the standard mouse pointer with one you design in Flash, you can
integrate the user’s mouse movement within the SWF file more closely. The sample in this section
uses a custom pointer that looks like a large arrow. The power of this feature, however, lies in your
ability to make the custom pointer look like anything—for example, a football to be carried to the
goal line or a swatch of fabric pulled over a couch to change its color.
To create a custom pointer, you design the pointer movie clip on the Stage. Then, in
ActionScript, you hide the standard pointer and track its the movement. To hide the standard
pointer, you use the
Mouse.hide()
method of the built-in Mouse class. To use a movie clip as the
custom pointer, you use the
startDrag()
action.
To create a custom pointer:
1
Create a movie clip to use as a custom pointer, and place an instance of the clip on the Stage.
2
Select the movie clip instance on the Stage.
3
Select Window > Development Panels > Actions to open the Actions panel if it is not
already visible.
4
Type the following in the Actions panel:
onClipEvent (load) {
Mouse.hide();
startDrag(this, true);
}
onClipEvent(mouseMove){
updateAfterEvent();
}
The first
onClipEvent()
handler hides the mouse when the movie clip first appears on the
Stage; the second handler calls
updateAfterEvent
whenever the user moves the mouse.
The
updateAfterEvent
function immediately refreshes the screen after the specified event
occurs, rather than when the next frame is drawn, which is the default behavior. (See
updateAfterEvent()
on page 743
.)
5
Select Control > Test Movie to test your custom pointer.
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...