MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference page 54

Actionscript language reference
Table of Contents

Advertisement

Private members (properties and methods) are accessible only to the class that defines those
members and to subclasses of that original class. Instances of the original class, or instances of
subclasses of that class, cannot access privately declared properties and methods; that is, private
members are accessible only within class definitions; not at the instance level.
For example, you could create a subclass of LoginClass called NewLoginClass. This subclass can
access the private property (
class NewLoginClass extends LoginClass {
// can access userName and getUserName()
}
However, an instance of LoginClass or NewLoginClass cannot access those private members. For
example, the following code would result in a compiler error indicating that
private and can't be accessed:
var loginObject:LoginClass = new LoginClass("Maxwell");
var user:String = loginObject.getUserName();
Member access control is a compile-time-only feature; at runtime, Flash Player does not
distinguish between private or public members.
The
keyword is not required in ActionScript 2.0 class definitions because the compiler
this
resolves the reference and adds it into the bytecode. However, using
readability..
Initializing properties inline
You can initialize properties inline—that is, when you declare them—with default values, as
shown in the following example:
class Person {
var age:Number = 50;
var name:String = "John Doe";
}
When you initialize properties inline, the expression on the right side of an assignment must be a
compile-time constant. That is, the expression cannot refer to anything that is set or defined at
runtime. Compile-time constants include string literals, numbers, Boolean values,
, as well as constructor functions for the following built-in classes: Array, Boolean,
undefined
Number, Object, and String.
For example, the following class definition initializes several properties inline:
class CompileTimeTest {
var foo:String = "my foo"; // OK
var bar:Number = 5; // OK
var bool:Boolean = true; // OK
var name:String = new String("Jane"); // OK
var who:String = foo; // OK, because 'foo' is a constant
var whee:String = myFunc(); // error! not compile-time constant expression
var lala:Number = whee; // error! not compile-time constant expression
var star:Number = bar + 25; // OK, both 'bar' and '25' are constants
function myFunc():String {
54
Chapter 2: Creating Custom Classes with ActionScript 2.0
) and method (
userName
) defined by LoginClass.
getUserName()
can improve your code's
this
is
getUserName()
, and
null

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flex

Table of Contents