Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 117

Programming actionscript 3.0
Table of Contents

Advertisement

Constructor methods can only be public, but the use of the
cannot use any of the other access control specifiers, including
, on a constructor. You also cannot use a user-defined namespace with a constructor
internal
method.
A constructor can make an explicit call to the constructor of its direct superclass using the
statement. If the superclass constructor is not explicitly called, the compiler
super()
automatically inserts a call before the first statement in the constructor body. You can also call
methods of the superclass using the
to use both
super()
Otherwise, the
super
also be called before any
The following example demonstrates what happens if you attempt to use the
before calling the
super()
The ExampleEx constructor attempts to access the status variable defined in its superclass, but
does so before calling
produces the value
null
constructor executes.
class ExampleEx extends Example
{
public function ExampleEx()
{
trace(super.status);
super();
}
}
var mySample:ExampleEx = new ExampleEx(); // output: null
Although it is legal to use the
return a value. In other words,
values. Accordingly, constructor methods are not allowed to return values, which means that
no return type may be specified.
If you do not define a constructor method in your class, the compiler will automatically create
an empty constructor for you. If your class extends another class class, the compiler will
include a
call in the constructor it generates.
super()
super
and
in the same constructor body, be sure to call
super
reference will not behave as expected. The
or
throw
return
constructor. A new class, ExampleEx, extends the Example class.
. The
super()
trace()
because the
status
statement inside a constructor, it is not permissible to
return
statements must not have associated expressions or
return
public
private
prefix as a reference to the superclass. If you decide
statement.
statement inside the ExampleEx constructor
variable is not available until the
attribute is optional. You
,
, or
protected
super()
constructor should
super()
reference
super
super()
Classes
first.
117

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents