Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Functions and Methods > About functions and methods > Defining global and timeline functions | |||
In About functions and methods, you explored the different kinds of functions that are available in Flash. As with variables, functions are attached to the timeline of the movie clip that defines them, and you must use a target path to call them. As with variables, you can use the _global identifier to declare a global function that is available to all timelines and scopes without using a target path. To define a global function, precede the function name with the identifier _global, as shown in the following example:
_global.myFunction = function(myNum:Number):Number {
return (myNum * 2) + 3;
};
trace(myFunction(5)) // 13
For information on _global and scope, About variables and scope.
To define a timeline function, use the function statement followed by the name of the function, any parameters to be passed to the function, and the ActionScript statements that indicate what the function does.
The following example is a function named areaOfCircle with the parameter radius:
function areaOfCircle(radius:Number):Number {
return (Math.PI * radius * radius);
}
trace(areaOfCircle(8));
You can also define functions in numerous other ways. For more information on each kind of function, see the following sections:
For information on naming functions, see Naming functions. For a detailed example of using functions in an external class file, see Using functions in Flash and Classes.
|
NOTE |
|
For information on writing code using Script Assist, see Using Flash. |
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000754.html