EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 202

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
202 Functions and Methods
If you pass values as parameters to a function, the function can perform calculations using the
supplied values. Each function has individual characteristics, and some functions require that
you pass certain types or numbers of values. If you pass more parameters than the function
requires, the function ignores the extra values. If you dont pass a required parameter, the
function assigns the
undefined data type to the empty parameters. This can cause errors
during runtime. A function can also return values (see “Returning values from functions
on page 220).
You can think of a well-written function as a “black box.” If the function contains carefully
placed comments about its input, output, and purpose, a person using the function does not
need to understand exactly how it works internally.
The basic syntax for a simple named function is:
function traceMe() {
trace("your message");
}
traceMe();
For information on writing named functions, see “Writing named functions” on page 207.
The basic syntax for a simple named function that builds on the previous example by passing
a parameter,
yourMessage, is:
function traceMe(yourMessage:String) {
trace(yourMessage);
}
traceMe("How you doing?");
Alternatively, if you want to pass multiple parameters, you could use the following code:
var yourName:String = "Ester";
var yourAge:String = "65";
var favSoftware:String = "Flash";
function traceMe(favSoftware:String, yourName:String, yourAge:String) {
trace("I'm " + yourName + ", I like " + favSoftware + ", and I'm " +
yourAge + ".");
}
traceMe(favSoftware,yourName,yourAge);
NOTE
To call a function, that function’s definition must be in a frame that the playhead has
reached.

Table of Contents

Related product manuals