casting between sibling classes, AS3
- by felix-gasca
I have two classes, derivedClassA and derivedClassB which both extend parentClass
I'm declaring var o:parentClass and then, depending on what's going on, I want to cast o as either being of type derivedClassA or derivedClassB.
Essentially, this:
var o:parentClass
...
if(shouldUseA)
o = new derivedClassA();
else
o = new derivedClassB();
o.doSomething();
But it's not working, I'm getting all sorts of errors. Isn't this how class inheritance works? I feel like I'm missing something really fundamental, but I can't figure out what. Am I supposed to be using interfaces instead? Is there another way of doing what I want?