如何在ActionScript 3中正确测试类继承? [英] How to properly test for class inheritance in ActionScript 3?

查看:143
本文介绍了如何在ActionScript 3中正确测试类继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ActionScript 3中,您可以确定对象O是类C还是使用...扩展或实现类C(直接或间接)的类。

In ActionScript 3, you can figure out whether object O is of class C or of a class that extends or implements class C (directly or indirectly) using...

if (O is C) {
    ...
}

我想做的是测试类CC是否扩展或实现类C(直接或间接),而不必实例化一个对象。

What I want to do is to test whether class CC extends or implements class C (directly or indirectly), without having to instantiate an object.

在Java中,您将使用...

In Java, you would use...

if (C.isAssignableFrom (CC)) {
    ...
}

http://java.sun.com/javase/6/docs/ api / java / lang / Class.html#isAssignableFrom(java.lang.Class)

ActionScript 3如何?

How about ActionScript 3?

谢谢!

推荐答案

你可以直接在CC上调用describeType您不必实例化对象。

You can call describeType() on CC directly. You do not have to instantiate the object.

var typeXML:XML = describeType(CC);
if(typeXML.factory.extendsClass.(@type=="C").length() > 0)
{
...

这不是我想要的那么干净,但我找不到更好的东西。

It's not as clean as I'd like but I can't find anything better.

(通过Amarghosh:[ http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType()] [1]

(via Amarghosh: [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType()][1] )

这篇关于如何在ActionScript 3中正确测试类继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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