MACROMEDIA FLASH MX 2004-USING ACTIONSCRIPT IN FLASH Use Manual page 264

Using actionscript in flash
Hide thumbs Also See for FLASH MX 2004-USING ACTIONSCRIPT IN FLASH:
Table of Contents

Advertisement

Another type of member is a class member. There is only one copy of a class member, which is
used for the entire class.
The
property would not be a good class member, because each person has a different age.
age
Only properties and methods that are shared by all individuals of the class should be class
members.
Suppose that you want every class to have a
name for the species that the class represents. For every Person object, the species is Homo
sapiens. It would be wasteful to store a unique copy of the string
instance of the class, so this member should be a class member.
Class members are declared with the
class member with the following code:
species
class Person
{
static var species:String = "Homo sapiens";
...
}
You can also declare methods of a class to be static, as shown in the following code:
static function functionName() {
// function body
}
Class (static) methods can access only class (static) properties, not instance properties. For
example, the following code will result in a compiler error because the class method
references the instance variable
class StaticTest {
var name:String="Ted";
static function getName():Void {
var local_name:String = name;
// Error! Instance variables cannot be accessed in static functions.
}
}
To solve this problem, you could either make the method an instance method or make the
variable a class variable.
A common use of class members is the Singleton design pattern. The Singleton design pattern
makes sure that a class has only one instance and provides a way of globally accessing the instance.
For more information on the Singleton design pattern, see
coldfusion/articles/design_patterns.html.
264
Chapter 10: Creating Custom Classes with ActionScript 2.0
species
modifier. For example, you could declare the
static
:
name
member that indicates the proper Latin
"Homo sapiens"
www.macromedia.com/devnet/mx/
for every
getName()

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-USING ACTIONSCRIPT IN FLASH and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Flash mx 2004 - actionscript

Table of Contents