Determine if the class that will be created is a children of another
For this example, I will use 2 classes, Entity and CSpawner. CSpawner is a children of Entity.
I want to perform the following condition:
if((new CSpawner()) is Entity)
It works just like intended.
But I want to do this test, without creating a new CSpawner object, something like this:
if(CS开发者_开发知识库pawner is Entity)
But it doesn't work, because CSpawner is a Class.
How do I perform that kind of conditional without creating a new CSpawner object?
Take a look at the describeType() function found under the flash.util package. It provides the kind of data you're looking for (both for instance objects and class objects).
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType()
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#getQualifiedSuperclassName() is what you are looking for. It returns the Super class name You can check the other methods from the utils package - this is ActionScript's basic reflection :)
精彩评论