Glen Pike wrote: > I am not sure about the "interpreted" bit - I can't remember to well, but > Colin Moock's AS3 book mentioned not putting too much code in a constructor > because of some constraint on the system - instead you should farm out > initialization to another function, e.g. > > public class MyClass { > public function MyClass() { > _init(); > } > > private function _init():void { > trace("doing lots of setup"); > //... > trace("finished setup..."); > } > }
Putting the initialization code in the init() function has a lot of advantages, like you can instantiate something, do an addChild(), then call init() when you're ready. As was noted a week or so ago, that allows you to listen for events in other objects via bubbling. I have another approach that is similar to yours, but keeps the call stack smaller: public function MyClass() { addEventListener(Event.ADDED, init, false, 0, true); } private function init(e:Event):void { removeEventListener(Event.ADDED, init); ... other init code } Cordially, Kerry Thompson _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders