Function Class

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Function Class Flash 6

object-oriented representation of ActionScript functions

Properties

prototype

An object specifying methods and properties for a class.

Methods

apply( )

Invoke a function as an object method, passing parameters in an array.

call( )

Invoke a function as an object method.

toString( )

Returns a string representation of the function object.

Description

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.

Usage

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;");

See Also

The Arguments object; Chapter 9, Chapter 12



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net