Write A Function - MACROMEDIA FLASH 8-FLASH Tutorials Manual

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

Advertisement

Write a function

A function is a script that you can use repeatedly to perform a specific task.
You can pass parameters to a function, and it can return a value. In this
lesson, every time your user clicks the Calculate button, a function will run
that multiplies data in the input text fields and returns values in the
dynamic text fields. You'll write that function now.
1.
In the Script pane, with the insertion point after the ActionScript that
reads
qty3_txt.text = 0;
(Macintosh) twice and type the following comment:
//Calculate quantity times price.
2.
Press Enter or Return and type the following to create a function that
runs when the playhead enters Frame 1, where you're attaching
the script:
this.onEnterFrame = function (){
3.
Type the following ActionScript to specify how the function should
multiply the values in the input text fields for the airplane:
price1_txt.text = Number (qty1_txt.text)*Number
(priceCD);
is the instance name that you gave to the top price input
price1_txt
text field on the Stage.
defines the text that should appear in the text field, which is the
.text
number of parts multiplied by the cost of the part: the $320 that you
set as the value for the
4.
Press Enter or Return, and type the following two lines:
price2_txt.text = Number (qty2_txt.text)*Number
(priceShocks);
price3_txt.text = Number (qty3_txt.text)*Number
(priceCover);
};
Your function should appear as follows:
//Calculate quantity times price.
this.onEnterFrame = function (){
price1_txt.text = Number (qty1_txt.text)*Number
(priceCD);
price2_txt.text = Number (qty2_txt.text)*Number
(priceShocks);
price3_txt.text = Number (qty3_txt.text)*Number
(priceCover);
};
, press Enter (Windows) or Return
variable.
priceCD
Write a function 103

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?

Questions and answers

Table of Contents

Save PDF