static
Availability
Flash Player 6.
Usage
class someClassName{
static var name;
static function name() {
// your statements here
}
}
Parameters
The name of the variable or function that you want to specify as static.
name
Description
Keyword; specifies that a variable or function is created only once per class rather than being
created in every object based on that class. For more information, see
members" on page
You can access a static class member without creating an instance of the class by using the syntax
someClassName.name
member using the instance.
You can use this keyword in class definitions only, not in interface definitions.
Example
The following example demonstrates how you can use the
that tracks how many instances of the class have been created. Because the
is static, it will be created only once for the entire class, not for every single instance. Create a new
AS file called Users.as and enter the following code:
class Users {
private static var numInstances:Number = 0;
function Users() {
numInstances++;
}
static function get instances():Number {
return numInstances;
}
}
Create a FLA or AS document in the same directory, and enter the following ActionScript:
trace(Users.instances);
var user1:Users = new Users();
trace(Users.instances);
var user2:Users = new Users();
trace(Users.instances);
See also
private,
public
206
Chapter 5: ActionScript Core Language Elements
ActionScript Core Language Elements
60.
. If you do create an instance of the class, you can also access a static
"Instance and class
keyword to create a counter
static
numInstances
CHAPTER 5
variable
Need help?
Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?
Questions and answers