----- Original Message ----- From: "Mendelsohn, Michael" <michael.mendels...@fmglobal.com>
To: "Flash Coders List" <flashcoders@chattyfig.figleaf.com>
Sent: Wednesday, February 18, 2009 9:12 PM
Subject: RE: [Flashcoders] component def doesn't pass params to constructor?


Thanks for responding Paul!

So going forward with my custom components, I was trying to avoid two
lines of code, but you're suggesting that?

//Instead of:
var cc:CustomComponent = new CustomComponent("red", 5);

//it's better to do:
var cc:CustomComponent = new CustomComponent();
cc.init("red", 5);

I thought one line of code would be a cleaner technique?

Some people prefer to use the constructor, others like init(). With a separate init() you can re-initialise an existing instance rather than create a new instance. You could even have multiple init() functions:

cc.initTexturedBall("red",5,roughTexture);

Your constructor can also call a default init().

etc.

It's not a black and white choice. Whatever it is, it's not an obstacle to getting to where you need to be.

Paul

- MM


That's a polarised view that isn't strictly true. If you're dragging
components to the stage in the IDE, how is the IDE supposed to
instantiate
the component with the appropriate parameters?

You can always achieve a similar effect by having a parameterless
constructor coupled with a parameterised init() method. Nothing stopping
you
having the same architecture for stage components and actionscript
created
class instances. In many ways, the parameterised init() is preferable to
a
parameterised constructor.

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to