9.6.1 Constructor methods

A function declared with the same identifier as the class it is defined in adds a constructor method to the class object. The constructor is called when a new instance of that class is created. A constructor may refer to the instance variables of the class that defines it.

class A 
{
    function A() {}
}

A constructor is public by default and may be defined with the public namespace or with no namespace attribute. If no constructor is defined by a class definition, a default constructor is defined implicitly. No more than one constructor can be defined for a class.

If the body of a constructor contains a SuperStatement, that statement must occur before the first reference to this or super, and before any return or throw statement. If a call to the super constructor is not explicit, one will be inserted before the first statement in the constructor body. Note the following errors:

NOTE

 

That there is no way to directly call the constructor of an indirect base class is intentional because it might lead to brittle or insecure programs.


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/specs/actionscript/3/as3_specification89.html