
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Methods
|
81
ActionScript 2.0 does not support ECMAScript 4’s enumerable
attribute, which makes an instance property visible to the for-in state-
ment. To make an instance property enumerable, you can use the
undocumented ASSetPropFlags( ) function. For details, see http://
chattyfig.figleaf.com/flashcoders-wiki/index.php?ASSetPropFlags
Methods
Methods are functions that determine the behavior of a class. They implement the
tasks that instances of the class or the class itself can perform. For example, Action-
Script’s built-in Sound class has a method named loadSound( ) that can retrieve an
external MP3 file for playback in the Flash Player.
To define methods for our own classes, we use the function statement within the
body of a class definition, as follows:
class ClassName {
function methodName (param1:type, param2:type,...paramn:type):returnType {
statements
}
}
where methodName is the identifier for the method; param1:type, param2:type, ...paramn:
type, is a list of the method’s parameters; returnType is the datatype of the method’s
return value; and
statements is zero or more statements executed when the method
is invoked. Each parameter definition (e.g.,
param1:type) consists of a parameter
name (
param1), a colon (:), and a type identifier (type), indicating the datatype of the
parameter. ...