MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 249

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

If you want to add a private property to the previous class, you simply use the keyword
before the
private
var
If you attempt to access the private
compiler error and a message in the Output panel. The message indicates that the member is
private and cannot be accessed.
Static methods and properties
The
keyword specifies that a variable or function is created only once per class rather
static
than in every object based on that class. You can access a static class member without creating
an instance of the class. Static methods and properties can be set in either the public or
private scope.
Static members, also called class members, are assigned to the class, not to any instance of the
class. To invoke a class method or access a class property, you reference the class name, rather
than a specific instance of the class, as shown in the following code:
trace(Math.PI / 8); // 0.392699081698724
If you type this single line of code in the script pane of the Actions panel, you see a result trace
in the Output panel.
For example, in the previous Sample class example, you could create a static variable to keep
track of how many instances of the class have been created, as demonstrated in the
following code:
class Sample {
public static var count:Number = 0;
private var ID:Number;
public var email:String;
public function Sample() {
Sample.count++;
trace("count updated: " + Sample.count);
}
public function myMethod():Void {
trace("myMethod");
}
}
Every time you create a new instance of the Sample class, the constructor method traces the
total number of Sample class instances that have been defined so far.
Some of the top-level ActionScript classes have class members (or static members), as you saw
earlier in this section when you called the
methods) are accessed or invoked on the class name, not on an instance of the class.
Therefore, you don't create an instance of the class to use those properties and methods.
keyword.
property from outside the Sample class, you get a
ID
Math.PI
About working with custom classes in an application
property. Class members (properties and
249

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents