I am unqualified to comment on this other than I am deeply grateful for the work you do.

- rami

P T Withington kirjoitti:
Here is a more-tested version of isSubclassOf:

var isSubclassOf = function (a:Class, b:Class) {
  if ($as3) {
    #passthrough {
      import flash.utils.getQualifiedSuperclassName;
      import flash.utils.getDefinitionByName;
    }#
    var c:Class = a;
    do {
      if (c === Object) { return false; }
      if (c.prototype is b) { return true; }
      var name:String = getQualifiedSuperclassName(c);
      c = null;
      if (name != null) {
        try {
          c = getDefinitionByName(name) cast Class;
        } catch (e:ReferenceError) {
          if ($debug) {
            Debug.warn("isSubclass: %w", e);
          }
        }
      }
    } while (c != null);
    return false;
  } else {
    return (a === b) || (a.prototype is b);
  }
};

Bugs:  The flex compiler is outwitting me.  If I ask `isSubclassOf(lz.text, 
lz.formatter)`, I get:

ReferenceError: Error #1065: Variable $lzsc$mixin$LzFormatter$LzView is not defined.
Which is whacky.  The definition of lz.text is:

  dynamic class LzText extends $lzsc$mixin$LzFormatter$LzView {

I think the flex compiler is being too clever and not defining the interstitial 
class in the linked application since there are no direct references to it.  
Maybe it would be better if we just defined our own internal class property to 
support isSubclassOf in as3.

On 2010-01-18, at 09:38, P T Withington wrote:

Yes I agree.  I think the best we can do is to define Class.isSubclassOf 
predicate, something like:

Class.isSubclassOf = function isSubclassOf(classA:Class, classB:Class):Boolean {
 if (classA === Object) { return false; }
 if (classA === classB) { return true; }
 if ($as3) {
   return 
isSubclassOf(flash.utils.getDefinitionByName(flas.utils.getQualifiedSuperclassName(classA)),
 classB);
 } else {
   return classA.prototype is classB;
 }
}

I'm testing this now...


Reply via email to