Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Functions and Methods > About functions and methods > Using variables in functions | |||
Local variables are valuable tools for organizing code and making it easy to understand. When a function uses local variables, it can hide its variables from all other scripts in the SWF file; local variables are invoked in the scope of the body of the function and cease to exist when the function exits. Flash also treats any parameters passed to a function as local variables.
|
NOTE |
You can also use regular variables in a function. However, if you modify regular variables, it is good practice to use script comments to document these modifications. |
To use variables in functions:
var myName:String = "Ester";
var myAge:String = "65";
var myFavSoftware:String = "Flash";
function traceMe(yourFavSoftware:String, yourName:String, yourAge:String) {
trace("I'm " + yourName + ", I like " + yourFavSoftware + ", and I'm " + yourAge + ".");
}
traceMe(myFavSoftware, myName, myAge);
For more information on passing parameters, see Passing parameters to a function. For more information on variables and data, see Data and Data Types
|
|
|
|