Static initialisers two ways.

Static initialisers are good ways of running code for a class before any instances of it are created. Very useful for setting up things like loggers or defining default styles for custom components. Two different methods of achieving this are outlined below.

The first method looks something like this:


 private static var classConstructed:Boolean = classConstruct();
 
private static function classConstruct():Boolean
 { 
    //do some initialising...
    return true;
 }

When the static variable classContructed gets initialised, it calls the static method classConstruct executing whatever initialisation code is needed.

The second method looks like this:

 
[Mixin] 
public class SomeClass 
{ 
    public static function init (systemManager:ISystemManager) :void 
    { 
        //do some initialising... 
    }

This method uses slightly less code as it hooks into Flex's built in initialisation. All classes that use the [Mixin] metadata tag have thier static init method called during the SystemManager's mx_internal docFrameHandler method.