0

I'm making a level editor for my game, and would like to be able to access a list of all the classes included in my game. I have a static function in my Main class:

public static function register(c:Class, category:String):void {
    if (classRegister[category] == null) {
        classRegister[category] = new Array();
    }           
    classRegister[category].push(c);        
}

Then, in each class I want registered, I put a static initializer:

{           
    Main.register(prototype.constructor, "motion");     
}

However, the static initializers only get called when the class first gets used. Is there a way for a class to force itself to be used right when the game starts? I'm aware that I could explicitly list all the registered classes in the Main file, but that's suboptimal in that the Main file would have to be edited whenever a new class is added that wants registration.

Thanks,

Varga

Alex Varga
  • 1,752
  • 2
  • 14
  • 17
  • Are your class actually referenced somewhere in the code? Are they compiled into the SWF? Also, if there are part of library (SWC), you have more options for the linking that may affect the answer. – Antoine Lassauzay Apr 20 '13 at 00:06

1 Answers1

0

List all the class definition in the ApplicationDomain, and filter them based on a naming convention or a type (an interface?).

To achieve this, you can use ApplicationDomain.getQualifiedDefinitionNames() (docs), but only if you target FlashPlayer 11.3+.

As a side note, you MUST reference this class somewhere, as a class field so the compiler knows it must include this class in the SWF. You can also put the classes you want to reference inside a SWC library and use -compiler.include-libraries as compiler setting (in that case I wonder if your static initializers gets called?).

Antoine Lassauzay
  • 1,557
  • 11
  • 12