I want to implement this method
function isInstance(a:Class, b:Class):Boolean;
This is how AS3 work with Classes. Note that MovieClip extends Sprite.
trace(MovieClip is Sprite); // false
trace(Sprite is MovieClip); // false
trace(Sprite is Sprite); // false
trace(Sprite is Object); // true
I been trying the next code but it is not working:
/**
* return if instance of class 'a' can be cast to instant of class 'b'
*/
private function isInstance(a:Class, b:Class):Boolean{
var superclass:Class = a;
do {
if (superclass == b) {
return true;
}
superclass = getSuperClass(a);
} while (superclass != null);
return false;
}
private function getSuperClass(claz:Class):Class{
var qualifiedSuperclassName:String = getQualifiedSuperclassName(claz);
var returnValue:Class = getDefinitionByName(qualifiedSuperclassName) as Class;
return returnValue;
}
From the ActionScript docs
And their samples:
It sounds to me like you're trying to do this the hard way.
Found solution in this site.
It is simple as that:
There is a use here of instanceof that been deprecated from as3. As I understood he cannot be replaced with is in this case, but correct me if I am wrong. Any way read the article before commenting.