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 don’t 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 " + yo ", I like " + favSo ", and I'm " +
y ".");
}
traceMe(favSoftware,yourName,yourAge);
NO
TE
To call a function, that function’s definition must be in a frame that the playhead has
reached.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...