Static Statement - MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE Reference

Flash lite 2.x actionscript language reference
Hide thumbs Also See for FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE:
Table of Contents

Advertisement

See also
var statement

static statement

class someClassName{ static var name; static function name() { // your
statements here } }
Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in
the Flash tab of your FLA file's Publish Settings dialog box. This keyword is supported only
when used in external script files, not in scripts written in the Actions panel.
Specifies that a variable or function is created only once per class rather than being created in
every object based on that class.
You can access a static class member without creating an instance of the class by using the
syntax
someClassName.name
static member using the instance, but only through a non-static function that accesses the
static member.
You can use this keyword in class definitions only, not in interface definitions.
Availability: ActionScript 2.0; Flash Lite 2.0
Parameters
- The name of the variable or function that you want to specify as static.
name:String
Example
The following example demonstrates how you can use the
counter that tracks how many instances of the class have been created. Because the
variable is static, it will be created only once for the entire class, not for every
numInstances
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;
}
}
. If you do create an instance of the class, you can also access a
keyword to create a
static
Statements
213

Advertisement

Table of Contents
loading

Table of Contents