Besides instantiating, how do you tell if ClassA is descending from ClassB to ActionScript?
I need to determine if one class descends (directly or indirectly) from another.
I can do
var testInstance : Object = new ClassA();
if (testInstance is ClassB)
...
but I hate instantiating just for checking pedigree. I was hoping if (ClassA - ClassB) would work, but it doesn't seem like it.
AS help states
isPrototypeOf (theClass: Object): Boolean
Indicates whether the Object instance is on the prototype chain of the object specified as a parameter.
I don't really understand ActionScript prototypes (I think it might drive me crazy), but I hope that class objects can somehow use inheritance information.
thank
source to share
Prototypes are instances of either class (for class inheritance) or parent class (for prototype inheritance). Try:
Object.prototype.extends=function (theClass:Object):boolean {
return this.prototype instanceof theClass;
}
ClassA.extends(ClassB);
ActionScript 3 trains a class-based inheritance prototype. You no longer use prototypes in ActionScript, but this is not a difficult concept and its use, so it would be useful for you to learn it. Read " History of OOP Support for ActionScript " and " Prototype Object " from " Advanced Themes "
source to share