Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 118

Programming actionscript 3.0
Table of Contents

Advertisement

Static methods
Static methods, also called class methods, are methods that are declared with the
keyword. Static methods, which are attached to a class rather than to an instance of a class, are
useful for encapsulating functionality that affects something other than the state of an
individual instance. Because static methods are attached to a class as a whole, static methods
can be accessed only through a class and not through an instance of the class.
Static methods are useful for encapsulating functionality that is not limited to affecting the
state of class instances. In other words, a method should be static if it provides functionality
that does not directly affect the value of a class instance. For example, the Date class has a
static method named
is static because it does not affect an individual instance of the class. Instead, the
method takes a string that represents a date value, parses the string, and returns a number in a
format compatible with the internal representation of a Date object. This method is not an
instance method because it does not make sense to apply the method to an instance of the
Date class.
Contrast the static
parse()
as
. The
getMonth()
on the value of an instance by retrieving a specific component, the month, of a Date instance.
Because static methods are not bound to individual instances, you cannot use the keywords
or
within the body of a static method. Both the
this
super
reference have meaning only within the context of an instance method.
In contrast with some other class-based programming languages, static methods in
ActionScript 3.0 are not inherited. For more information, see
on page
136.
Instance methods
Instance methods are methods that are declared without the
methods, which are attached to instances of a class instead of the class as a whole, are useful
for implementing functionality that affects individual instances of a class. For example, the
Array class contains an instance method named
instances.
118
Object-Oriented Programming in ActionScript
, which takes a string and converts it to a number. The method
parse()
method with one of the instance methods of the Date class, such
method is an instance method because it operates directly
getMonth()
reference and the
this
"Static properties not inherited"
keyword. Instance
static
, which operates directly on Array
sort()
static
parse()
super

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents