MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 221

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

The following rules govern how to use the
If you specify a return type other than Void for a function, you must include a
statement and it must be followed by the returned value in the function.
If you specify a return type of Void, you do not need to include a
you do, it must not be followed by any value.
Regardless of the return type, you can use a
function.
If you don't specify a return type, including a
For example, the following function returns the square of the parameter
that the returned value must be a Number data type:
function sqr(myNum:Number):Number {
return myNum * myNum;
}
Some functions perform a series of tasks without returning a value. The next example returns
the processed value. You are capturing that value in a variable, and then you can use that
variable within your application.
To return a value and capture it in a variable:
1.
Create a new Flash document and save it as return.fla.
2.
Add the following code to Frame 1 of the main Timeline:
function getArea(width:Number, height:Number):Number {
return width * height;
}
The
function takes two parameters,
getArea()
3.
Type the following code after the function:
var area:Number = getArea(10, 12);
trace(area); // 120
The
function call assigns the values 10 and 12 to the width and height,
getArea()
respectively, and you save the return value in the
that you save in the
4.
Select Control > Test Movie to test the SWF file.
You see
in the Output panel.
120
The parameters in the
exist while the function is called and cease to exist when the function exits.
return
instance.
area
function are similar to values in a local variable; they
getArea()
statement in functions:
statement to exit from the middle of a
return
statement is optional.
return
and
width
height
instance. Then you trace the values
area
About functions and methods
return
statement, but if
return
and specifies
myNum
.
221

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents