Why doesn't mxml support component constructors?

Why doesn't the Flex mxml Flex environment support constructor for components or accept constructor arguments for components? As far as I know, it is not possible to declare an ActionScript object in mxml if it takes constructor arguments. I am curious why. Is this an Adobe design choice, or is it related to how declarative languages ​​work? For example, why not allow:

<myNameSpace:MyComponent constructor="{argArray}"/> 
+7
source share
2 answers

You can read the IMXMLObject help API for more information about your question. They do not report why mxml does not support constructors, but it says that you should control your mxml component through your life events: preinitialize, initialize and creationComplete.

I assume that the design decision, considering that mxml is translated directly into AS3 code (you can compile your application by adding keep-generated-actionscript = true and see what it produces).

+6
source

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> 
+4
source

All Articles