The DataGrid does not like having popups come up during edit sessions. It is trying to manage focus between editors as the popup tries to take away the focus. There's also a 'problem' in your code that itemEditEnd can be called twice, once as you leave the cell, and again as the dg tries to move to a new cell and you lose focus to the popup and have to kill that editor too. I'd add logic as to whether you have a popup up or not, I would also regenerate the popup every time instead of re-using it and set focus in the creationComplete handler to the button in the popup. There may still be cases that won't work. I'd try to avoid this kind of UI if possible, popups are rather jarring. What are you really trying to popup? What's the user task goal?
________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of wpbarto Sent: Tuesday, December 11, 2007 2:14 PM To: [email protected] Subject: [flexcoders] PopupManager causes RangeError: Error #2006: adding a popup window I saw something else similar in flexcoders, but the information didn't seem to apply to this case. I can create a popup window from a button's click handler, but THE SAME CODE used when editing a DataGrid cell FAILS! Is it a bug or a mis-use of PopupManager?? Thanks for any help! Top part of Error stack: RangeError: Error #2006: The supplied index is out of bounds. at flash.display::DisplayObjectContainer/addChildAt() at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal: <http://www.adobe.com/2006/flex/mx/internal:> :rawChildren_addChildAt() at mx.managers::SystemManager/addChild() at mx.managers::PopUpManagerImpl/addPopUp() at mx.managers::PopUpManager$/addPopUp() at TestPopup/::onCellEdit() at TestPopup/__pointGrid_itemEditEnd() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEv entFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent() at mx.controls::DataGrid/::endEdit() at mx.controls::DataGrid/::deactivateHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEv entFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent() at mx.controls::DataGrid/::endEdit() This is the smallest example I can create: [File1: TestPopup.mxml] ================================================================== <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " layout="absolute" applicationComplete="onAppComplete()"> <mx:Script> <![CDATA[ import mx.managers.PopUpManager; import mx.collections.ArrayCollection; import mx.events.DataGridEvent; import mx.events.DataGridEventReason; private var popWin:MyPopupWindow = null; private var curData:ArrayCollection; // items for datagrid private var items:ArrayCollection; // items for pop up private function onAppComplete():void { curData = new ArrayCollection(); curData.addItem( { ident:"ORD", cityname:"Chicago, IL" } ); curData.addItem( { ident:"ATL", cityname:"Atlanta, GA" } ); curData.addItem( { ident:"DEN", cityname:"Denver, CO" } ); curData.addItem( { ident:"", cityname:"" } ); // one blank pointGrid.rowCount = 5; pointGrid.dataProvider = curData; items = new ArrayCollection(); items.addItem( {ident:"JFK", cityname:"New York, NY"} ); items.addItem( {ident:"LAX", cityname:"Los Angeles, CA"} ); items.addItem( {ident:"SEA", cityname:"Seattle, WA"} ); } private function onClick():void { if(popWin == null) { popWin = new MyPopupWindow(); popWin.itemChoices = items; } PopUpManager.addPopUp(popWin, this, true); PopUpManager.centerPopUp(popWin); } private function onCellEdit(event:DataGridEvent):void { if(event.reason == DataGridEventReason.CANCELLED) return; if(popWin == null) { popWin = new MyPopupWindow(); popWin.itemChoices = items; } PopUpManager.addPopUp(popWin, this, true); PopUpManager.centerPopUp(popWin); } ]]> </mx:Script> <mx:VBox> <mx:Label text="Clicking the button creates popup OK:" /> <mx:Button id="theButton" label="Click Me" click="onClick()"/> <mx:Label text="However, editing a cell FIRST fails:" /> <mx:DataGrid id="pointGrid" itemEditEnd="onCellEdit(event)" editable="true"> <mx:columns> <mx:DataGridColumn id="identCol" width="50" dataField="ident" headerText="Ident"/> <mx:DataGridColumn id="citynameCol" width="90" dataField="cityname" headerText="City/Name" paddingLeft="1" paddingRight="1"/> </mx:columns> </mx:DataGrid> </mx:VBox> </mx:Application> [File2: MyPopupWindow.mxml] ================================================================== <?xml version="1.0" encoding="utf-8"?> <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " layout="absolute" width="400" height="300" title="The Popup Window"> <mx:DataGrid id="selItemList" dataProvider="{itemChoices}" width="100%" height="100%"> <mx:columns> <mx:DataGridColumn id="identCol" dataField="ident" headerText="Ident"/> <mx:DataGridColumn id="typeCol" dataField="cityname" headerText="City"/> </mx:columns> </mx:DataGrid> <mx:ControlBar width="100%"> <mx:Spacer width="100%"/> <mx:Button label="Cancel" click="onCancel()"/> </mx:ControlBar> <mx:Script> <![CDATA[ import mx.managers.PopUpManager; import mx.collections.ArrayCollection; [Bindable] public var itemChoices:ArrayCollection = new ArrayCollection(); private function onCancel():void { PopUpManager.removePopUp(this); } ]]> </mx:Script> </mx:Panel>

