您当前的位置: 首页 > 

Jave.Lin

暂无认证

  • 2浏览

    0关注

    704博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

AS3 判断某个类型(注意:不是实例)是否继承于某个类型的方法

Jave.Lin 发布时间:2013-12-25 10:52:58 ,浏览量:2

在未找到有现有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;
		}

关注
打赏
1664331872
查看更多评论
立即登录/注册

微信扫码登录

0.0448s