Write An Event Handler For The Component - MACROMEDIA FLASH 8-FLASH Tutorials Manual

Hide thumbs Also See for FLASH 8-FLASH:
Table of Contents

Advertisement

104 Basic Tasks: Create an Application
Write an event handler for the
component
For your SWF file to react to events such as a mouse click, you can use
event handlers—ActionScript associated with a particular object and event.
You'll use an
event handler for the Button component that calculates
on()
the total price when users click the button.
For more information about event handlers, see
Learning ActionScript 2.0 in Flash.
1.
On the Stage, click the Button component and go to the Actions panel.
The tab at the bottom of the Actions panel, labeled Calculate, indicates
that you're attaching the script directly to the selected object rather
than to a frame.
2.
In the Script pane, type the following comment:
//Calculates total price.
3.
After the comment, press Enter (Windows) or Return (Macintosh) and
type the following to create a handler for the PushButton component
that you placed on the Stage:
on(click) {
You just typed the start of the
specifies that the event should occur when the user clicks the Calculate
button.
A Button component has its own Timeline. In the Timeline hierarchy,
the component Timeline is a child of the main Timeline. To point to
elements from the Button component Timeline to the main Timeline
in this script, you use the code
4.
With the insertion point at the end of the line you just typed, press
Enter or Return and type the following:
with(_parent){
5.
Press Enter or Return and complete your handler by typing the
following:
priceTotal_txt.text = Number (price1_txt.text) + Number
(price2_txt.text) + Number (price3_txt.text);
}
}
"Handling Events"
event handler. The
on()
.
with (_parent)
in
(click)

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF