actionscript 3 - In AS3, how do I run code when a when the movie starts? -


i'm making level editor game, , able access list of classes included in game. have static function in 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 want registered, put static initializer:

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

however, static initializers called when class first gets used. there way class force used right when game starts? i'm aware explicitly list registered classes in main file, that's suboptimal in main file have edited whenever new class added wants registration.

thanks,

varga

list class definition in applicationdomain, , filter them based on naming convention or type (an interface?).

to achieve this, can use applicationdomain.getqualifieddefinitionnames() (docs), if target flashplayer 11.3+.

as side note, must reference class somewhere, class field compiler knows must include class in swf. can put classes want reference inside swc library , use -compiler.include-libraries compiler setting (in case wonder if static initializers gets called?).


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -