Why don't you try ttlwQuery.addEventListener(FlexEvent.SHOW, functionToSetFocus);
I'd also recommend not creating the titleWindow inside the loadQueryCanvas, it would be better to create as separate class which is a titlewindow that you can then create and show. See http://blog.flexexamples.com/2008/08/16/creating-an-undraggable-titlewin dow-container-in-flex/ for an example if I'm not making sense J P.S I've know people to use private paste to show there code. http://privatepaste.com/ Handy especially as pasting code into an email normally makes it unreadable. HTH, Kenneth. From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of aceoohay Sent: 15 September 2008 15:36 To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: How can I set focus to a field in a programatically created popup? Kenneth: Thanks for the response. That is precisely how I have done it in the past as well. Unfortunately, I do not know how to create functions "on-the-fly." I am creating the entire object using AS code and then displaying it in a popup. Is there a way of creating a new function in an object as you create it? If so I could create an initApp() function and call it from creationComplete. Also is there a better way of posting code so that it doesn't lose its formatting? Paul --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "Kenneth Sutherland" <[EMAIL PROTECTED]> wrote: > > I haven't tried your code but I would normally do what you're doing > using the show event. > > > > e.g. show="fieldToGetFocus.setFocus();" > > > > this would go inside of your popup code. > > > > From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> [mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> ] On > Behalf Of aceoohay > Sent: 15 September 2008 07:38 > To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> > Subject: [flexcoders] How can I set focus to a field in a > programatically created popup? > > > > I am creating a titlewindow with some fields completely in AS3 > script. I then display this object using a popup. I want to set focus > to the very first field in the popped up titlewindow. > > I have tried a number of things, the most promising (I thought) was > to add a creation complete event listener. This did not work. > > All ideas welcome, here is the code; > > public function loadQueryCanvas():void > { > _ttlwQuery = new TitleWindow; > _hbQuery = new HBox; > _dgDisplay = new DataGrid; > // _ttlwQuery.width = 200; > // _ttlwQuery.height = 200; > _ttlwQuery.showCloseButton = true; > _ttlwQuery.title = _title; > _ttlwQuery.addEventListener > (CloseEvent.CLOSE,closePopup); > /* var intX:int = _targetTextBox["x"]; > var intY:int = _targetTextBox["y"] + > _targetTextBox["height"] + 2; > _ttlwQuery.x = intX; > _ttlwQuery.y = intY; > */ > var cvsQuery:Canvas = new Canvas; > _hbQuery.height = 25; > var txtField:ValidatedTextInput; > var lblField:Label; > var dgColumn:DataGridColumn; > var aryColumns:Array = new Array; > var intTabIndex:int = 0; > for each (var objItem:Object in > _searchFields) > { > if (objItem["Input"] == "Y") > { > lblField = new Label > lblField.text = > objItem["Label"] + ":"; > lblField.id > = "lbl" + objItem["Field"]; > lblField..setStyle > ("fontWeight","bold"); > _hbQuery.addChild > (lblField); > txtField = new > ValidatedTextInput; > txtField.name > = "txt" + objItem["Field"]; > txtField.width = > objItem["Width"]; > txtField.maxChars = > objItem["MaxChars"]; > txtField.dataType = > objItem["DataType"]; > > txtField.charactersAlsoPermitted = "%_"; > txtField.tabIndex = > intTabIndex; > intTabIndex++; > if (!_txtFirstField) > _txtFirstField = txtField; > _hbQuery.addChild > (txtField); > } > dgColumn = new DataGridColumn > (); > dgColumn.dataField = objItem > ["Field"]; > dgColumn.width = objItem > ["Width"]; > dgColumn.headerText = objItem > ["Label"]; > aryColumns.push(dgColumn); > } > var btnSearch:Button = new Button; > btnSearch.id = "btnSearch"; > btnSearch.label = "Search" > btnSearch.addEventListener > (MouseEvent.CLICK,doSearch); > _hbQuery.addChild(btnSearch); > _hbQuery.defaultButton = btnSearch; > _dgDisplay.id = "_dgDisplay"; > _dgDisplay.columns = aryColumns; > // _dgDisplay.dataProvider = > _acDataTable; > _dgDisplay.x = 0; > _dgDisplay.y = 26; > _dgDisplay.height = > _targetTextBox.parent.height - 100; > _dgDisplay.percentWidth = 100; > _dgDisplay.addEventListener > (ListEvent.ITEM_CLICK,_dgDisplaySelected); > // _dgDisplay.addEventListener > (DataGridEvent.HEADER_RELEASE,headerReleaseHandler); > cvsQuery.addChild(_hbQuery); > cvsQuery.addChild(_dgDisplay); > _ttlwQuery.addChild(cvsQuery); > > _ttlwQuery.visible = true; > _ttlwQuery.addEventListener > (FlexEvent.CREATION_COMPLETE,setPopupFocus); > PopUpManager.addPopUp(_ttlwQuery, > _targetTextBox.parent, true); > PopUpManager.centerPopUp(_ttlwQuery); > > // var event:Event; > // doSearch(event); > // _targetTextBox.parent.addChild > (_ttlwQuery); > > } > public function setPopupFocus > (event:Event):void > { > _ttlwQuery.focusManager.setFocus > (_ttlwQuery.focusManager.getNextFocusManagerComponent()); > } > > > > Disclaimer > ---------------------------------------------------------- ------------------------ > This electronic message contains information which may be privileged and confidential. The information is intended to be for the use of the individual(s) or entity named above. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this electronic message in error, please notify us by telephone on 0131 476 6000 and delete the material from your computer. > Registered in Scotland number: SC 172507. > Registered office address: Quay House 142 Commercial Street Edinburgh EH6 6LB. > > This email message has been scanned for viruses by Mimecast. > ---------------------------------------------------------- ------------------------ > Disclaimer ------------------------------------------------------------------------------------------- This electronic message contains information which may be privileged and confidential. The information is intended to be for the use of the individual(s) or entity named above. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this electronic message in error, please notify us by telephone on 0131 476 6000 and delete the material from your computer. Registered in Scotland number: SC 172507. Registered office address: Quay House 142 Commercial Street Edinburgh EH6 6LB. This email message has been scanned for viruses by Mimecast. -------------------------------------------------------------------------------------------