I have x amount of classes in a package eg. “com.trevorboyle.lotsofclasses” and I keep adding more (These classes will probably all be static and will probably all extend the same class).
I wish to create a drop-down list of all these classes, preferably without having to manually create an array myself.
Once a class is selected from the list, I’ll be able to use getDefinitionByName to return it, because I will know it’s name at this point.
The question is, as I believe there is no support in AS3 to list all the classes in a specific package, is there a design pattern that handles this?
There are two ways:
First, traditional clean as3 implementation:
Create a class that registers all the classes of your interest at class initialization (when it’s first used in code).
Something like this:
}
Class registered on initialization:
}
And there is another, not tested by myself but very promising:
Use as3commons bytecode library.
Class ByteCodeTypeCache in property
definitionNamesstores all fully qualified definition names that have been encountered in all the bytecode that was scanned. You can just iterate through that list and take what you need. Of course you have to make sure that all classes you will need on runtime is compiled into bytecode (you have to initialize those classes somewhere or use as3 compiler directives).