我有两个类型定义,我怎么能确定的是对方的基类型? [英] I have two type definitions, how can I determine if one is a base type of the other?

查看:106
本文介绍了我有两个类型定义,我怎么能确定的是对方的基类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个类型定义(Class类型的引用)在ActionScript 3,我需要弄清楚如果是其他的基本类型(类或接口)。

I have two type definitions (references of type Class) in ActionScript 3 and I need to figure out if one is a base type (class or interface) of the other.

我希望像下面这样的工作,但可惜事实并非如此:

I had hoped something like the following would work, but alas it did not:

var isBaseClass:Boolean = MouseEvent is Event;

这是可以理解为什么它没有,但它仍然是不错的。我不能使用不如describeType要么,因为对于Class类型的对象,它实际上并没有返回正确的继承链,而是只返回类型的类和对象,这不利于在所有。我的可以的使用getQualifiedSuperClassName在一个循环,直到有没有更多的超类或存在匹配,但它不够理想和对接口的类型检查不能正常工作。

It is understandable why it doesn't, but it would still be nice. I can't use describeType either, since for objects of type Class it doesn't actually return the correct inheritance chain but rather just return the types Class and Object, which doesn't help at all. I can use getQualifiedSuperClassName in a loop until either there are no more super classes or there is a match, but it's less than ideal and doesn't work for type checking against interfaces.

任何人都有一个更好的主意吗?

Anyone have a better idea?

推荐答案

下面使用不如describeType没有问题的一个活生生的例子: http://wonderfl.net/c/h90R

Here a live example using describeType with no problem : http://wonderfl.net/c/h90R

trace(describeType(MouseEvent)..extendsClass)

输出:

<extendsClass type="Class"/>
<extendsClass type="Object"/>
<extendsClass type="flash.events::Event"/>
<extendsClass type="Object"/>

这篇关于我有两个类型定义,我怎么能确定的是对方的基类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆