How to get all subclasses of a class (in AS3)
This is a little odd but I need to know all subclasses of a specific class. So let's say I have the base class called Shape and 3 subclasses (Circle, Triangle开发者_运维百科 and Rectangle) that implement it. I would like something like this :
public function getSubclasses(aClass : Class) : Vector.<Class>
{
//???
}
that returns a vector containing Circle, Triangle and Rectangle.
I unfortunately cannot count on the fact that each subclass be instanciated at least once before that function is called.
At the moment I need to manually add the classes to a list but this is error prone (if I forget) and also not as versatile as the function proposed above would be (since I would need to make a new list for every class I want the subclasses of).
Thanks!
There's no built-in function to do that in Flash. You can use reflection to get the base class of a class, but not the other way around (see flash.utils.describeType()
).
@Laurent is right. To go further I would say it is not possible at all. If you have a class, you can tell wether or not it is a child of another (by instanciating it) but there is no way to list available classes in AS3.
精彩评论