
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
212
|
Chapter 9: Functions
is not reset (reinitialized) every time the function is called. As a general rule, function
properties should be used only to store information that pertains to the function.
More general information should be stored either in a class or as a global variable.
ActionScript functions can also have other functions attached to them, which can be
used to simulate Java-style static class methods. For example:
function SomeClass ( ) {
// Constructor code goes here.
}
SomeClass.staticMethod = function ( ) {
// Static method code goes here.
}
where SomeClass is the name of the class and staticMethod is the name of the static
method.
For examples of function methods, see the built-in Function.call( ) and Function.apply( )
methods in the Language Reference. These methods execute a function in the context
of a specified object. We’ll revisit static methods and the
prototype property in
Chapter 12.
Returning Functions from Functions
Finally, because function objects are data, they can be returned by functions. The fol-
lowing example shows a function, makeGotoHandler( ), that returns a nested func-
tion literal for use as the callback of a movie clip event handler. The function literal
sends the clip’s playhead to the frame specified by
frameNumber.
function makeGotoHandler (frameNumber) ...