15.3 Super statement

A SuperStatement causes the constructor of the immediate base class to be called. If no SuperStatement is specified, the default constructor of the base class is called. Unlike in Java, a SuperStatement may be used anywhere in the body of the constructor before an instance property is accessed. It is a compile error to use more than one SuperStatement in a constructor.

Syntax

SuperStatement

 

super Arguments

A SuperStatement may only be used inside a constructor. It is a syntax error to use a SuperStatement anywhere else in a program.

class B extends A {
    function B(x,y,z) {
        super(x,y)
        // other constructor code here
    }
}

Semantics

Compatibility

In ActionScript 2.0, a SuperStatement may be used anywhere in a program, except in a static method of a class. It is equivalent to the following statement:

this.constructor.prototype.constructor.apply(this,arguments)

If used in a class instance function, it will call the class's constructor function using the current value of this as the first argument. If used in global code, it will call the global object's class's super constructor.

In ActionScript 3.0, a SuperStatement may only be used in an instance constructor. All other uses will result in a syntax error. Also, if the number and types of Arguments is not compatible with Parameters of the super constructor, the result is a runtime error.


 

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

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