I’m using a library that has a function that returns an instance of some class Engine.
I’d like to tack on some interfaces to Engine, so I subclass it class InterfacedEngine extends Engine implements AwesomeInterface.
But when I change the code that uses the classes from this:
var engine:Engine = generateEngine();
to this:
var interfacedEngine:InterfacedEngine = generateEngine();
It gives me a runtime error (elision mine):
TypeError: Error #1034: Type Coercion failed: cannot convert ...::Engine@1bc2bf11 to ....InterfacedEngine.
What about AS3 classes am I misunderstanding?
If B is the base class and D extends B then a D is a B, but not the opposite. That means a reference of type B can refer to both B and D. But a reference of type D can only refer to D, not B.
InterfacedEnginecan only referInterfacedEngine, not it’s baseEngine. But aEnginetype can refer to bothEngineandInterfacedEngine.