Extends
[subclass, superclass] → []

Adobe documentation

ActionExtends

ActionExtends implements the ActionScript extends keyword. ActionExtends creates an inheritance relationship between two classes, called the subclass and the superclass.

SWF 7 adds ActionExtends to the file format to avoid spurious calls to the superclass constructor function (which would occur when inheritance was established under ActionScript 1.0). Consider the following code:

Subclass.prototype = new Superclass();

Before the existence of ActionExtends, this code would result in a spurious call to the Superclass superconstructor function. Now, ActionExtends is generated by the ActionScript compiler when the code class A extends B is encountered, to set up the inheritance relationship between A and B.

FieldTypeComment
ActionCastOpACTIONRECORDHEADERActionCode = 0x69

ActionExtends does the following:

  1. Pops the ScriptObject superclass constructor off the stack.

  2. Pops the ScriptObject subclass constructor off the stack.

  3. Creates a new ScriptObject.

  4. Sets the new ScriptObject’s proto property to the superclass’ prototype property.

  5. Sets the new ScriptObject’s constructor property to the superclass.

  6. Sets the subclass’ prototype property to the new ScriptObject. These steps are the equivalent to the following ActionScript:

    Subclass.prototype = new Object();
    Subclass.prototype. proto = Superclass.prototype;
    Subclass.prototype. constructor = Superclass;