There's no issue with createChildren but with the way how and when to decide to set properties on sub-components. If you want the component in my example to have a close button, you usually set the hasClosebutton to true in a overriden createChildren method. The problem is that normally the children are created first and then you set properties like the hasCloseButton, i.e. you call super.createChildren() first and then set properties.
But that will run into null refs sooner or later, hence the use of listening to a creationComplete event but as I said that can't be the best way to archieve this. Sascha From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of Tracy Spratt Sent: Tuesday, April 21, 2009 11:48 To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Best way to defer sub-component initialization? What is your issue with using createChildren()? Tracy Spratt, Lariat Services, development services available _____ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of Sascha Sent: Monday, April 20, 2009 10:43 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Best way to defer sub-component initialization? Not sure if the subject makes complete sense but what would be the best way to defer setting properties on a sub component when writing custom Flex components without getting a null reference? Let's say I create a custom component that wraps another component, for example a button ... package { class Foo extends Panel { protected var _closeButton:Button; protected var _hasCloseButton:Boolean; public function Foo() { super(); } public function set hasCloseButtton(v:Boolean):void { _hasCloseButton = v; } override protected function createChildren():void { super.createChildren(); if (_hasCloseButton) { _closeButton = new Button(); addChild(_closeButton); } } } } There are two ways that I know how to get the close button, either in an extending class in the overriding createChildren method set _hasCloseButton = true _and then_ call super.createChildren() or the other way by listening for a creationComplete event and defer/handle the instantiation of the close button from there on. But I think these two ways are sub-optimal so I was wondering how others solve this problem and what works best in every situation? Thanks for any advice! Sascha _._,___