Tải bản đầy đủ (.pdf) (14 trang)

Tài liệu Using Mouse Events ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (31.49 KB, 14 trang )


< Day Day Up >

Using Mouse Events
Mouse events control the execution of scripts when the mouse interacts with a button or
movie clip instance. You use them to emulate things you might do with your hands.
Making Contact: on (press)
In the physical world, when you touch or press something—a person or an ice cube—you
expect a reaction: the person responds, the ice cube melts. The on (press) event handler
works great for emulating touching, grabbing, or just plain pushing, as well as the results
of any of these actions. You can use this event handler to trigger a script when the cursor
is above a button or movie clip instance and the mouse button is pressed.

Letting Go: on (release)
When you release something or cease to make contact with it, you're usually finished
interacting with it and ready to move on. This event handler—which emulates letting go
of something (or dropping it)—is the most direct way of allowing the user to make your
movie take action. It's often used on buttons or movie clip instances to trigger actions.
You use it to trigger a script when the mouse button is released (it was first pressed while
it was over a button or movie clip instance).

Pulling, Snapping: on (releaseOutside)
Imagine a deck of cards sitting on a table: you push down on the top card with your
finger, drag it away from the deck, and then let your finger up. In Flash, this deck of
cards could represent a button that the user presses, drags away from, then releases. You
can use this event handler to trigger a script when your user has pressed a movie button
or movie clip instance but released the mouse away from it, making this event handler
useful for emulating pulling or snapping.

Keyboard Control: on (keyPress)
You use this event to program your movie to trigger a script when a user presses a letter,


number, punctuation mark, symbol, or arrow key; or the Backspace, Insert, Home, End,
Page Up, or Page Down key.
Over But Not Touching: on (rollOver)
You can place your hand over a hot stove and feel the heat without actually touching the
stove. Consider using this event handler to emulate the way objects are affected by other
objects that radiate heat, cold, light, air, and so on—with the button or movie clip
instance as the radiation source. You can also use this event handler to display
information about what a button or movie clip instance does before it's pressed (similar to
a ToolTip or an HTML hotspot graphic). You employ this event handler to trigger a
script when the user places his or her mouse over a button or movie clip instance.

No Longer On Top Of: on (rollOut)
Obviously, when you move your hand away from that stove, you cease to feel the heat it's
radiating and your hand cools down. That's what this event handler emulates. You can
use this event handler to trigger a script when the user moves the mouse away from a
button or movie clip instance it was formerly over.

Grooves, Bumps, Rubbing: on (dragOver)
The act of rubbing entails a back-and-forth motion across an area. When a shoe is being
shined (cloth dragged over it), for example, it gets slicker with each pass (action). This
event handler lets you emulate this type of activity in your movie by triggering a script
each time the mouse passes over the same movie button or movie clip instance while the
mouse button remains pressed.

Oops: on (dragOut)
This event handler allows you to emulate what can happen when you press or touch
something but then pull away—as if you were to touch someone by accident and quickly
pull your hand away once you realize your mistake. You can use this event handler to
trigger a script when the user places the pointer over a movie button or movie clip
instance, presses the mouse button, and drags it away from the movie button or movie

clip instance (while still pressing the mouse button).

In this exercise, we'll create a fingerprint scanner that interacts with the user in various
ways. In the process, you'll learn several creative uses for these event handlers, enabling
you to emulate rubbing, snapping, and more.
1. Open MouseEvents1.fla in the Lesson02/Assets folder. Open the Scene panel and
Property Inspector.
We're focusing on the ActionScript that makes this project work, so most of the
elements are already in place. Let's get acquainted with what's on the stage.
The Scene panel shows that our project contains two scenes, Scan and Playroom.
We'll begin our work in the Scan scene, which contains five layers that are named
according to their content.
If you select the box in the bottom center of the screen, you'll see in the Property
Inspector that this is a dynamic text field with an instance name of message_mc.
If you select the hand graphic, you'll notice in the Property Inspector that this is a
movie clip instance named hand_mc. The black box in the middle of the screen is
also a movie clip instance; this one is named scanner_mc. On top of this movie
clip instance is a button that appears to be a square piece of glass. Soon we'll
attach several scripts to this button.

2. Lock the Scanner button layer and double-click the scanner movie clip instance in
the middle of the stage to edit it in place.
You are now looking at this movie clip's timeline. The overall functionality of this
movie clip is not important (move the playhead to see how it appears visually at
various points). It is, however, important to be aware of the six frame labels on its
timeline. One of the functions of the several scripts we'll attach to our Glass button
(on the main timeline) will be to move this movie clip's timeline to these various
labels whenever a particular mouse event occurs.
3. Return to the main timeline. With the Actions panel open, select Frame 1 of the
Actions layer and add the script:

4.
5.
6. stop ();
7.
8. Mouse.hide();
9.
10. startDrag ("hand_mc", true);
11.
12. message_txt.text = "Please place your finger on the scanner and press down.
Release after
13.
14. 2 seconds.";

×