2010-03-08 7 views
0
interface If { ... } 
class Impl implements If { ... } 

function test(type:Class, obj) { 
    return obj instanceof type; 
} 

test(If, new Impl());

L'appel à test sur la dernière ligne renvoie false, mais il doit être true. Comment puis-je faire ce contrôle correctement, avec l'exigence qu'il doit être à l'intérieur de la fonction?ActionScript instanceof pour l'interface dynamique


Code réel:

public function iterate(callback:Function, type:Class = null) { 
     for (var node:EntityListNode = beginNode; node != null; node = node.next) { 
      if (type == null || node.entity instanceof type) callback(node.entity); 
     } 
    } 

Répondre

1

if(Object is IInterface) ... fonctionne très bien pour ce AFAIK.