What happened to constructor parameters?
by Ruben
Having been working alot with components in AS3 lately, it just struck me that most of the components have no parameters in their constructors.
I can see that when using MXML there is no need for constructor parameters (since properties are attributes), but I can seriously see the use for this in Actionscript, since common properties fit in there without making the code look ugly.
The next block of code, for example, would easily fit on one line, making it compact, and still be readable:
var myInstance:OtherClass = new OtherClass(); public function MyClass ():void { myInstance.width = 300; myInstance.height = 400; }
So is there some kind of harm done by properties as constructor parameters that I am missing?
Comments (read older)
Hi guys,
So to complete what soem of you are saying, I think the best way to deal with it is to create as many private variables as you need in your custom component.
Set them after immediatly you create a new instance of it:
cc = new CustomComponent()
cc.var1 = …
(though I think using set functions it’s better practice)
Then, inside your custom MXML component:
creationComplete=”initialize()” …>