Functions
are used to group blocks of code so that
they can be called with a simple statement
and reused when nessecary.
To use a custom function it must first
be defined. The term new function tell
flash that a new function is being created.
function
function_name() :datatype{
statements
} |
- "function_name" is
the name given to the function. This
is used to call the function later. Function
should be named using names that describe
what the function does. This makes it
easyer to work with code
- "datatype" is
the type of data that you want the function
to return. For example: "number" returns
a result of the function in the form
of a number or .....
- "statements" are
the actionscript statements that desacribe
the actions that you want the function
to perform.
Example I:
This function "sshow_text_when_called"
is designed to display text in the actionscript
output panel.
function sshow_text_when_called()
:Void{
trace("Hello World.");
} |
Each time the
function is called the words "Hello World"
appear in the output window.
Example II:
This function is
designed to perform a simple mathematical
calculation and return the result as a
number.
|
function
ncalculate_value() :Number{
130+22*9;
} |
function n
Example III:
This function is designed to reset the
position of the movie clip "car_mc" to
the coordinates (150, 200) on the stage.
function
reset_mc_position (car_mc:MovieClip)
:Void {
car_mc._x = 150;
car_mc._y = 200;
} |
A function can be called by using its
unique name