This content has been marked as final. Show 6 replies
I do not believe you can do that. In fact, I seem to recall the the constructor must have no arguments.
Does the compiler not tell you that?
Thanks for your reply.
The error I get in the Flex Builder is
"Incorrect number of arguments".
Tracy's correct; you cannot have a constructor with MXML components. If you want to do that, use an ActionScript class instead. As long as the class extends a visual class (eg, Canvas, ComboBox, etc) you can use it in MXML as a tag.
So how would you pass arguments to the constructor of an as class instantiated in mxml?
You cannot do that. The code generated from the MXML tag only calls the constructor without any arguments. I think the compiler would complain if the constructor had 1 or more arguments; you'd definitely get a runtime error.
If you really need to pass data to a class when it is created in MXML, use its initialize event:
<MyTag initialize="event.target.initMoi(arg1,arg2,arg3)" />
Something somewhat similar is to create an AS class that extends IMXMLObject. The IMXMLObject interface defines a
initialized(document:Object, id:String):void function. You can define use to initlize things through a the class.
But you can do the same with initialize event and custom functions.