Write An Event Handler For The Component - MACROMEDIA FLASH MX 2004-LEARNING FLASH Manual

Learning flash
Table of Contents

Advertisement

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
the Button component that calculates the total price when users click the button.
For more information about event handlers, see "Handling Events" in Using ActionScript in Flash.
On the Stage, click the Button component and go to the Actions panel.
1.
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.
In the Script pane, type the following comment:
2.
//Calculates total price
After the comment, press Return or Enter and type the following to create a handler for the
3.
PushButton component that you placed on the Stage:
on(click) {
You just typed the start of the
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
With the insertion point at the end of the line you just typed, press Enter or Return and type
4.
the following:
with(_parent){
Press Enter or Return and complete your handler by typing the following:
5.
priceTotal_txt.text = Number (price1_txt.text) + Number (price2_txt.text) +
Number (price3_txt.text);
}
}
When you finish, your script should appear as follows:
on(click) {
with(_parent){
priceTotal_txt.text = Number (price1_txt.text) + Number (price2_txt.text)
+ Number (price3_txt.text);
}
}
The event handler that you typed specifies that the text in the priceTotal_txt field should be the
sum of the values in the Price1_txt, Price2_txt, and Price3_txt fields.
event handler. The
on()
Write an event handler for the component
event handler for
on()
specifies that the event should
(click)
with (_parent)
.
39

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Questions and answers

This manual is also suitable for:

Flash mx 2004 - actionscript

Table of Contents