Even if the class is defined in MXML, you can implement the constructor through an instance of an instance variable as follows. This will be called before various events are sent, such as "preinitialize" or "creationComplete".
<myNameSpace:MyComponent> <fx:Script> <![CDATA[ private var ignored:* = myInstanceConstructor(); private function myInstanceConstructor():* { // Do something - called once per instance return null; } ]]> </fx:Script> </myNameSpace:MyComponent>
In addition, class variables can be initialized as follows.
<myNameSpace:MyComponent> <fx:Script> <![CDATA[ private static var ignored:* = myClassConstructor(); private static function myClassConstructor():* { // Do something - called once per class return null; } ]]> </fx:Script> </myNameSpace:MyComponent>
Cq bear
source share