Write A Function - MACROMEDIA FLASH MX 2004-LEARNING FLASH Manual

Learning flash
Table of Contents

Advertisement

Press Enter or Return and type the following two lines to set values of 0 for the other two
3.
QTY fields:
qty2_txt.text = 0;
qty3_txt.text = 0;
When you finish, the ActionScript should appear as follows:
//set initial values for the quantity text fields
qty1_txt.text = 0;
qty2_txt.text = 0;
qty3_txt.text = 0;

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.
In the Script pane, with the insertion point after the ActionScript that reads
1.
, press Enter or Return twice and type the following comment:
0;
//calculate quantity times price
Press Enter or Return and type the following to create a function that runs when the playhead
2.
enters Frame 1, where you're attaching the script:
this.onEnterFrame = function (){
Type the following ActionScript to specify how the function should multiply the values in the
3.
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 text field on the Stage.
price1_txt
defines the text that should appear in the text field, which is the number of parts
.text
multiplied by the cost of the part: the $320 that you set as the value for the
Press Enter or return and type the following two lines:
4.
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);
};
38
Chapter 4: Create an Application
qty3_txt.text =
variable.
priceCD

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

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash mx 2004 - actionscript

Table of Contents