views:

219

answers:

3

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) {
    ...
}

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.

In Java, you would use...

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

http://java.sun.com/javase/6/docs/api/java/lang/Class.html#isAssignableFrom%28java.lang.Class%29

How about ActionScript 3?

Thanks!

+1  A: 

I think , you will have to manually parse through the XML object returned by flash.utils.describeType

codegasm
There is not a way to determine the type simply by looking at the class (except by using `flash.utils.describeType`). You can only do this by instantiating the object first.
Mims H. Wright
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType()
Amarghosh
*parentheses are part of the link
Amarghosh
Thank you for the pointer to that method.
jmdecombe
+1  A: 

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.

(via Amarghosh: [http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType%28%29%5D%5B1%5D )

Nate Austin
Great, thanks. Coming from the rich Java 6 API, I find myself having to reinvent the wheel all the time with Flash/Flex, grrr ;-).
jmdecombe
A: 

Alternatively, if you use as3commons-reflect package (which is very, very useful, by the way), you can call:

ClassUtils.getImplementedInterfaces(CC)
David Wolever