Checking constructor compatibility

This originally appeared on my blog back in October 2007.

I needed to compare two Class objects in AS3 today, to work out if one was a descendant from another - note neither of these are instances (which you could just compare with a simple if (a is SomeClass)), they are both uninstantiated.

This is what I came up with, after a bit of fiddling.

public static function isClassCompatibleWith(test:Class,desired:Class):Boolean
{
    var search:String=describeType(desired).@name;
    var desc:XML=describeType(test);
    if (desc.factory.extendsClass.(@type==search).length()>0)
        return true;
    if (desc.factory.implementsInterface.(@type==search).length()>0)
        return true;
    return false;
}

Might be handy for someone.