在未找到有现有API时,只能自己利用别的API来实现:
/**
* @author Jave.Lin
* @date 2013-12-25
* AS3 判断某个类型(注意:不是实例)是否继承于某个类型的方法
* @param targetCls 指定要判断的目标类型
* @param specialCls 指定要判断是否继承的类型
* @return 如果是,返回true,否则返回false
*
*
*
* e.g:
* public class A{}
* public class B exnteds A {} // 继承于A
*
* var result:Boolean = targetClsIsInheritSpecialCls(B, A); // 判断B类型,是否继承于A类型
* trace(result); // out put true
*
* public class C{} // 没有继承用户指定类型,当然,默认会继承于:Object类型
*
* result = targetClsIsInheritSpecialCls(C, B); // 判断C类型,是否继承于B类型
* trace(result); // out put false
*
*
*/
public static function targetClsIsInheritSpecialCls(targetCls:Class, specialCls:Class):Boolean
{
if(!targetCls || !specialCls) return false;
var targetClsStr:String = getQualifiedClassName(targetCls);
while(targetClsStr != null)
{
var superCls:Class = getDefinitionByName(targetClsStr) as Class;
if(superCls == specialCls) return true;
targetClsStr = getQualifiedSuperclassName(superCls);
}
return false;
}