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