I see three problems: 1. This code gives an RTE when I run it. When the Application's creationComplete handler calls createTextArea(), and this method executes addChild(titleWindows), titleWindows is null. You can't add a null child to a parent. 2. If you are using the PopUpManager to pop up TitleWindows on top of the Application, you don't want to be adding a TitleWindow as a child of the Application. 3. You create a single TextArea and then add it to multiple TitleWindows. When you add it to the second one, it gets automatically removed from the first one. A DisplayObject can only be parented by a single DisplayObjectContainer. - Gordon ________________________________
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Igor Costa Sent: Saturday, February 17, 2007 8:32 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] addChild doesn't work as dynamic, why? Hi there Folks While trying to create a dynamic component into flex application then trying to include others, why such thing doesn't work. In the example bellow I create an PopUp titleWindow with children TextArea Component. But when I create again the same titleWindow, the last TextArea who is children of titleWindow is removed. <?xml version="1.0" encoding="utf-8"?> <mx:Application creationComplete="createTextArea();" xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " layout="absolute"> <mx:Script> <![CDATA[ import mx.events.ChildExistenceChangedEvent; import mx.states.AddChild; import mx.controls.TextArea ; import mx.managers.PopUpManager; import mx.containers.TitleWindow; import mx.core.IFlexDisplayObject; public var titleWindows:TitleWindow; public var MyTextArea:TextArea; public var i:Number = Math.random() *50; private function createTitleWindow():void { titleWindows = new TitleWindow(); titleWindows.title = "Basic"; titleWindows.width = 330; titleWindows.height = 200; titleWindows.showCloseButton = true; titleWindows.addChild(MyTextArea); mx.managers.PopUpManager.addPopUp(titleWindows,this,false,null); titleWindows.creationPolicy ="all"; titleWindows.createReferenceOnParentDocument (MyTextArea); } private function createTextArea():void { MyTextArea = new TextArea(); MyTextArea.uid = 'textA'; MyTextArea.width = 330; MyTextArea.height = 200; MyTextArea.text = "Example of Dynamic Text Content"; MyTextArea.cacheAsBitmap = true; addChild(titleWindows); } ]]> </mx:Script> <mx:Button mouseDown="createTitleWindow()" label="Add dynamic Title Window with content"/> </mx:Application> Regards. -- ---------------------------- Igor Costa www.igorcosta.org <http://www.igorcosta.org> www.igorcosta.com <http://www.igorcosta.com> skype: igorpcosta