Inheritance in ActionScript 2.0

Back in the good old days of Flash 5 and MX, trying to do inheritance in ActionScript required some knowledge of what goes on behind the scene. Also, the infamous superclass invocation bug haunted developers for almost three years.

Now in ActionScript 2.0, with the new OOP-specific keywords, inheritance is much simpler:

1

2

3

4

5

6

7

classParent{

}

classChildextendsParent{

}

That’s all. And the keyword “super()” in the Child class constructor is not even mandatory because the compiler inserts it for you!

As for the superclass invocation bug, it is now fix for Flash player 7!

Post navigation

14 thoughts on “Inheritance in ActionScript 2.0”

Hi Dave,
Does the compiler also provide the default (no-args) constructor if we omit it in the class definition (as expected)?
Also, -afaik- there is no method overloading in AS 2.0 (at least in this release), so there will be no constructor overloading. How do we simulate constructor overloading? By providing various static methods that return instances of our class?

That’s right, there is no overloading of the constructor in AS2 because it all compiles down to AS1. To simulate constructor overloading, you’d do the same thing as in AS1. The simplest solution is to check arguments.length and handle differently.

I’m not sure if I follow “By providing various static methods that return instances of our class”. Could you elaborate?

how do you do this in AS1, I rem there were problems with inheritance in AS1 are they fixed in player7. I want to do it in AS1 so that I can dynamically create a class and have it inherit from another one and not be tied to a specific file name/class name. Any ideas greatly recieved.

The code is very interesting I have made some progress but it appears that the ‘static’ methodClass only works on the class not on any instances of the class? should it be in the constructor or is there something missing?

I have been working for last 3+ years with Flash, C, C++, VB, PHP etc.
Lately i have started feeling that i am not good in OOP. I wonder whats the best way to learn it, how to get started, what examples to do?