Function Class | Flash 6 |
object-oriented representation of ActionScript functions |
An object specifying methods and properties for a class.
Invoke a function as an object method, passing parameters in an array.
Invoke a function as an object method.
Returns a string representation of the function object.
In ActionScript, every function, both user-defined and built-in, is an instance of the Function class. As an object, every function can have properties and methods, and every function can be stored, passed, and compared as ActionScript data. While functions-as-objects is a foreign (and perhaps strange) concept to some programmers, it is a core component of the ECMA-262 implementation of object-oriented programming. In ActionScript, every function has the potential to be used as a class constructor. Hence, every function defines a prototype property specifying the methods and properties that will be inherited by the instances of the class. Furthermore, every function has the potential to be used as a method. Hence, every function can be stored as an object property (defining it as a method for that object). These and other uses of functions in ActionScript's inheritance system are discussed in Chapter 12.
Although functions were objects in Flash 5, it was not until Flash 6 that the Function class was formally exposed in ActionScript (at which time the apply( ) and call( ) methods were added, providing specialized tools for invoking functions as methods of arbitrary objects).
Some commands originally implemented in Flash 4 (e.g., getURL( ) and trace( )) work like functions but are actually compiled to their own bytecodes, are not members of the Function class, and do not have prototype properties.
For general information on creating and using functions in ActionScript, see Chapter 9.
Note that new Function objects cannot be created with the Function constructor in ActionScript. All functions must be defined with either the function statement or a function literal. For example, the following code is legal in JavaScript, but not in ActionScript:
var divide = new Function ("numerator", "divisor", "return numerator/divisor;");
The Arguments object; Chapter 9, Chapter 12