Functions are blocks of code that carry out specific tasks and can be reused in your program.There are two types of functions in ActionScript 3.0: methods and function closures. Whether a function is a called a method or a function closure depends on the context in which the function is defined. A function is called a method if you define it as part of a class definition or attach it to an instance of an object. A function is called a function closure if it is defined in any other way.
Functions have always been extremely important in ActionScript. In ActionScript 1, for example, the class keyword does not exist, so “classes” are defined by constructor functions. Although the class keyword has since been added to the language, a solid understanding of functions is still important if you want to take full advantage of what the language has to offer. This can be a challenge for programmers who expect ActionScript functions to behave similarly to functions in languages such as C++ or Java. While basic function definition and invocation should not present a challenge to experienced programmers, some of the more advanced features of ActionScript functions will most likely require explanation.
Basic concepts
This section discusses basic function definition and invocation techniques.
- Calling functions
- Defining your own functions
- Function statement
- Function Literal
- Choosing between statements and literals
- Returning values from functions