Public methods and properties
The
keyword specifies that a variable or function is available to any caller. Because
public
variables and functions are public by default, the
and readability benefits, indicating that the variable exists in the current scope. For example,
you might want to use the
private or static variables. The
private keyword.
The following Sample class already has a public method named
class Sample {
private var ID:Number;
public function myMethod():Void {
this.ID = 15;
trace(this.ID); // 15
trace("myMethod");
}
}
If you want to add a
can see in the following sample code:
class Sample {
private var ID:Number;
public var email:String;
public function myMethod():Void {
trace("myMethod");
}
}
Because the
property is public, you can change it within the Sample class, or directly
email
within a FLA.
Private methods and properties
The
keyword specifies that a variable or function is available only to the class that
private
declares or defines it or to subclasses of that class. By default, a variable or function is public,
and available to any caller. Use the
function, as you can see in the following example:
class Sample {
private var ID:Number;
public function myMethod():Void {
this.ID = 15;
trace(this.ID); // 15
trace("myMethod");
}
}
248
Classes
keyword for consistency in a block of code that also contains
this
keyword can be used with either the public or
this
property, you use the word "public" instead of "private," as you
public
keyword if you want to restrict access to a variable or
this
keyword is used primarily for stylistic
this
myMethod()
:
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?