Since ActionScript 2.0 does not have the “abstract” modifier, here’s one way to create a class that acts like an abstract class, by making the constructor private:
class PretendToBeAbstractClass {
// private constructor
private function PretendToBeAbstractClass() {}
}
When the following statement is compiled, the compiler will complain that one can’t instantiate from this class because the constructor is private:
var o:PretendToBeAbstractClass = new PretendToBeAbstractClass();
Although the constructor is private, but because it behaves as protected, you can still extend this class:
class MyClass extends PretendToBeAbstractClass {
}
What is missing is the compiler does not actually know what an abstract class is; therefore there won’t be any warning messages.
As I mentioned in the last post, you can get around all the type-checking at runtime, and even instantiating an “abstract†class at runtime like this:
var o = new _global["PretendToBeAbstractClass"]();
Or even access “private†properties from it:
trace(o.somePrivateVar);
Obviously these actions defeat the purpose of strict-typing, but it is possible (until runtime type-checking is implemented).