![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
For your SWF file to react to events such as a mouse click, you can use event handlersActionScript associated with a particular object and event. You'll use an on()
event handler for the Button component that calculates the total price when users click the button.
For more information about event handlers, see "Handling Events" in ActionScript Reference Guide Help.
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.
//Calculates total price
on(click) {
You just typed the start of the on()
event handler. The (click)
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 with (_parent)
.
with(_parent){
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.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |