![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
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.
qty3_txt.text = 0;
, press Enter or Return twice and type the following comment:
//calculate quantity times price
this.onEnterFrame = function (){
price1_txt.text = Number (qty1_txt.text)*Number (priceCD);
price1_txt
is the instance name that you gave to the top price input text field on the Stage.
.text
defines the text that should appear in the text field, which is the number of parts multiplied by the cost of the part: the $320 that you set as the value for the priceCD variable.
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); };
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |