Reply to comment

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.

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <h1> <h2> <h3> <h4> <h5> <i> <tt> <b> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <image>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options