RE: [flexcoders] ComboBox in Component won't open to Saved Value
Here's the code for a BindableComboBox. Save it in a file called BindableComboBox.mxml (borrowed this code from Adobe, modified slightly): mx:ComboBox xmlns:mx=http://www.adobe.com/2006/mxml; creationComplete=initComponent() mx:Script ![CDATA[ import mx.utils.ObjectUtil; import mx.controls.Alert; [Bindable] public var valueField:String = ; [Bindable] public var labelFields:Array = []; public function initComponent():void { this.labelFunction = renderLabelFunction; } public function renderLabelFunction(item:Object):String { var result:String = ; if (labelFields.length == 0) { if (labelField != null) { return item[labelField]; } else { return item.toString(); } } else { for (var i:int=0; i labelFields.length; i++) { if (i 0) { result += ; } result += item[labelFields[i]]; } } return result; } override public function set selectedItem(val:Object):void { if (this.valueField != null) { for (var i:int=0; i this.dataProvider.source.length; i++) { var item:Object = this.dataProvider.source[i]; if (item[valueField] == val) { this.selectedIndex = i; break; } } } else { super.selectedItem(val); } } public function get selectedItemValue():Object { if (this.valueField != null selectedItem != null) { return selectedItem[valueField]; } else { return text; } } ]] /mx:Script /mx:ComboBox Use it in your components as follows: Get the data back from the database (or webservice, or wherever) into an ArrayCollection that has the fields myID and myName for each item in the combo box. Then, assign the AC to the dataProvider of the BindableComboBox and use the component in your mxml code like this: mycoms:BindableComboBox id=myComboBox valueField=myID labelFields=[myName]/ I also have a search-as-you-type BindableComboBox that's a combination of this component with an auto-complete component I found on the web (not Adobe's) if you're interested. HTH, ~randy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tracy Spratt Sent: Wednesday, October 08, 2008 10:05 AM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value ComboBox.selectedItem will only work if you assign a *reference to an item in the ComboBox dataProvider*. This is rarely possible and is not in your case. What you must do is loop over the items in the CobmoBox.dataProvider and compare the appropriate property's value to the value you want to match. When a match is found, use the loop indes to set the ComboBox's selectedIndex. This is simple enough to do in a one-off situation. If you need this often, then you might want to use an extended ComboBox. Making a generic one is a bit tricky, because the Combo Box dataProvider items can have any properties at all. I have an example on www.cflex.net http://www.cflex.net/ (it allows you to set the data field you want to match) and Ben forta has done one and there are others. Tracy _ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:01 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] ComboBox in Component won't open to Saved Value Hi I have a ComboBox used as a Popup on a form component. It saves fine using the following function private function closeGenderPop(event:Event):void { ComboBox(event.target).selectedItem.label}; I want to have it display the stored value the next time it is opened. I tried this but no luck. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; ComboBox(event.target).selectedItem.label; } Really appreciate the help Dan Pride
[flexcoders] ComboBox in Component won't open to Saved Value
Hi I have a ComboBox used as a Popup on a form component. It saves fine using the following function private function closeGenderPop(event:Event):void { ComboBox(event.target).selectedItem.label}; I want to have it display the stored value the next time it is opened. I tried this but no luck. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; ComboBox(event.target).selectedItem.label; } Really appreciate the help Dan Pride
RE: [flexcoders] ComboBox in Component won't open to Saved Value
ComboBox.selectedItem will only work if you assign a *reference to an item in the ComboBox dataProvider*. This is rarely possible and is not in your case. What you must do is loop over the items in the CobmoBox.dataProvider and compare the appropriate property's value to the value you want to match. When a match is found, use the loop indes to set the ComboBox's selectedIndex. This is simple enough to do in a one-off situation. If you need this often, then you might want to use an extended ComboBox. Making a generic one is a bit tricky, because the Combo Box dataProvider items can have any properties at all. I have an example on www.cflex.net http://www.cflex.net/ (it allows you to set the data field you want to match) and Ben forta has done one and there are others. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:01 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] ComboBox in Component won't open to Saved Value Hi I have a ComboBox used as a Popup on a form component. It saves fine using the following function private function closeGenderPop(event:Event):void { ComboBox(event.target).selectedItem.label}; I want to have it display the stored value the next time it is opened. I tried this but no luck. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; ComboBox(event.target).selectedItem.label; } Really appreciate the help Dan Pride
RE: [flexcoders] ComboBox in Component won't open to Saved Value
Thanks for the response. I understand what needs to be done as you described but I still have one problem. I tried this before. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; } The ComboBox opened to the zero value not the 1. When I clicked on the box it opened to have the 1 value preselectect but did not present upon opening. I am referencing it like this and must be missing some kind of kick event? mx:ComboBox id=genderPop close=closeGenderPop(event) open=openGenderPop(event) dataProvider={arrGender} x=583.5 y=89 width=116 / Thanks again. This board is GREAT ! Dan Pride --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] wrote: From: Tracy Spratt [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 11:05 AM ComboBox.selectedItem will only work if you assign a *reference to an item in the ComboBox dataProvider*. This is rarely possible and is not in your case. What you must do is loop over the items in the CobmoBox.dataProvider and compare the appropriate property's value to the value you want to match. When a match is found, use the loop indes to set the ComboBox's selectedIndex. This is simple enough to do in a one-off situation. If you need this often, then you might want to use an extended ComboBox. Making a generic one is a bit tricky, because the Combo Box dataProvider items can have any properties at all. I have an example on www.cflex.net http://www.cflex.net/ (it allows you to set the data field you want to match) and Ben forta has done one and there are others. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:01 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] ComboBox in Component won't open to Saved Value Hi I have a ComboBox used as a Popup on a form component. It saves fine using the following function private function closeGenderPop(event:Event):void { ComboBox(event.target).selectedItem.label}; I want to have it display the stored value the next time it is opened. I tried this but no luck. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; ComboBox(event.target).selectedItem.label; } Really appreciate the help Dan Pride
RE: [flexcoders] ComboBox in Component won't open to Saved Value
Why are you doing that in the open event? Try creationComplete instead. Or set it directly without the function. Or bind selectedIndex to a bindable variable. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:57 AM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value Thanks for the response. I understand what needs to be done as you described but I still have one problem. I tried this before. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; } The ComboBox opened to the zero value not the 1. When I clicked on the box it opened to have the 1 value preselectect but did not present upon opening. I am referencing it like this and must be missing some kind of kick event? mx:ComboBox id=genderPop close=closeGenderPop(event) open=openGenderPop(event) dataProvider={arrGender} x=583.5 y=89 width=116 / Thanks again. This board is GREAT ! Dan Pride --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com wrote: From: Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Date: Wednesday, October 8, 2008, 11:05 AM ComboBox.selectedItem will only work if you assign a *reference to an item in the ComboBox dataProvider*. This is rarely possible and is not in your case. What you must do is loop over the items in the CobmoBox.dataProvider and compare the appropriate property's value to the value you want to match. When a match is found, use the loop indes to set the ComboBox's selectedIndex. This is simple enough to do in a one-off situation. If you need this often, then you might want to use an extended ComboBox. Making a generic one is a bit tricky, because the Combo Box dataProvider items can have any properties at all. I have an example on www.cflex.net http://www.cflex.net/ http://www.cflex.net/ (it allows you to set the data field you want to match) and Ben forta has done one and there are others. Tracy From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:01 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] ComboBox in Component won't open to Saved Value Hi I have a ComboBox used as a Popup on a form component. It saves fine using the following function private function closeGenderPop(event:Event):void { ComboBox(event.target).selectedItem.label}; I want to have it display the stored value the next time it is opened. I tried this but no luck. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; ComboBox(event.target).selectedItem.label; } Really appreciate the help Dan Pride
RE: [flexcoders] ComboBox in Component won't open to Saved Value
As Homer would say doh ! Thanks Dan --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] wrote: From: Tracy Spratt [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 11:34 AM Why are you doing that in the open event? Try creationComplete instead. Or set it directly without the function. Or bind selectedIndex to a bindable variable. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:57 AM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value Thanks for the response. I understand what needs to be done as you described but I still have one problem. I tried this before. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; } The ComboBox opened to the zero value not the 1. When I clicked on the box it opened to have the 1 value preselectect but did not present upon opening. I am referencing it like this and must be missing some kind of kick event? mx:ComboBox id=genderPop close=closeGenderPop(event) open=openGenderPop(event) dataProvider={arrGender} x=583.5 y=89 width=116 / Thanks again. This board is GREAT ! Dan Pride --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com wrote: From: Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Date: Wednesday, October 8, 2008, 11:05 AM ComboBox.selectedItem will only work if you assign a *reference to an item in the ComboBox dataProvider*. This is rarely possible and is not in your case. What you must do is loop over the items in the CobmoBox.dataProvider and compare the appropriate property's value to the value you want to match. When a match is found, use the loop indes to set the ComboBox's selectedIndex. This is simple enough to do in a one-off situation. If you need this often, then you might want to use an extended ComboBox. Making a generic one is a bit tricky, because the Combo Box dataProvider items can have any properties at all. I have an example on www.cflex.net http://www.cflex.net/ http://www.cflex.net/ (it allows you to set the data field you want to match) and Ben forta has done one and there are others. Tracy From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:01 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] ComboBox in Component won't open to Saved Value Hi I have a ComboBox used as a Popup on a form component. It saves fine using the following function private function closeGenderPop(event:Event):void { ComboBox(event.target).selectedItem.label}; I want to have it display the stored value the next time it is opened. I tried this but no luck. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; ComboBox(event.target).selectedItem.label; } Really appreciate the help Dan Pride
RE: [flexcoders] ComboBox in Component won't open to Saved Value
Creation complete works the first time but the component is displayed when you click on a list, and subsequent selections are not displayed. I am having trouble figuring out which on is the correct event.? Sorry but I am relatively new at this kind of programming. Thanks Dan --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] wrote: From: Tracy Spratt [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 11:34 AM Why are you doing that in the open event? Try creationComplete instead. Or set it directly without the function. Or bind selectedIndex to a bindable variable. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:57 AM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value Thanks for the response. I understand what needs to be done as you described but I still have one problem. I tried this before. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; } The ComboBox opened to the zero value not the 1. When I clicked on the box it opened to have the 1 value preselectect but did not present upon opening. I am referencing it like this and must be missing some kind of kick event? mx:ComboBox id=genderPop close=closeGenderPop(event) open=openGenderPop(event) dataProvider={arrGender} x=583.5 y=89 width=116 / Thanks again. This board is GREAT ! Dan Pride --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com wrote: From: Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Date: Wednesday, October 8, 2008, 11:05 AM ComboBox.selectedItem will only work if you assign a *reference to an item in the ComboBox dataProvider*. This is rarely possible and is not in your case. What you must do is loop over the items in the CobmoBox.dataProvider and compare the appropriate property's value to the value you want to match. When a match is found, use the loop indes to set the ComboBox's selectedIndex. This is simple enough to do in a one-off situation. If you need this often, then you might want to use an extended ComboBox. Making a generic one is a bit tricky, because the Combo Box dataProvider items can have any properties at all. I have an example on www.cflex.net http://www.cflex.net/ http://www.cflex.net/ (it allows you to set the data field you want to match) and Ben forta has done one and there are others. Tracy From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:01 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] ComboBox in Component won't open to Saved Value Hi I have a ComboBox used as a Popup on a form component. It saves fine using the following function private function closeGenderPop(event:Event):void { ComboBox(event.target).selectedItem.label}; I want to have it display the stored value the next time it is opened. I tried this but no luck. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; ComboBox(event.target).selectedItem.label; } Really appreciate the help Dan Pride
RE: [flexcoders] ComboBox in Component won't open to Saved Value
Creation complete works the first time but the component is displayed when you click on a list, and subsequent selections are not displayed. I am having trouble figuring out which on is the correct event.? Sorry but I am relatively new at this kind of programming. Thanks Dan --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] wrote: From: Tracy Spratt [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 11:34 AM Why are you doing that in the open event? Try creationComplete instead. Or set it directly without the function. Or bind selectedIndex to a bindable variable. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:57 AM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value Thanks for the response. I understand what needs to be done as you described but I still have one problem. I tried this before. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; } The ComboBox opened to the zero value not the 1. When I clicked on the box it opened to have the 1 value preselectect but did not present upon opening. I am referencing it like this and must be missing some kind of kick event? mx:ComboBox id=genderPop close=closeGenderPop(event) open=openGenderPop(event) dataProvider={arrGender} x=583.5 y=89 width=116 / Thanks again. This board is GREAT ! Dan Pride --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com wrote: From: Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Date: Wednesday, October 8, 2008, 11:05 AM ComboBox.selectedItem will only work if you assign a *reference to an item in the ComboBox dataProvider*. This is rarely possible and is not in your case. What you must do is loop over the items in the CobmoBox.dataProvider and compare the appropriate property's value to the value you want to match. When a match is found, use the loop indes to set the ComboBox's selectedIndex. This is simple enough to do in a one-off situation. If you need this often, then you might want to use an extended ComboBox. Making a generic one is a bit tricky, because the Combo Box dataProvider items can have any properties at all. I have an example on www.cflex.net http://www.cflex.net/ http://www.cflex.net/ (it allows you to set the data field you want to match) and Ben forta has done one and there are others. Tracy From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:01 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] ComboBox in Component won't open to Saved Value Hi I have a ComboBox used as a Popup on a form component. It saves fine using the following function private function closeGenderPop(event:Event):void { ComboBox(event.target).selectedItem.label}; I want to have it display the stored value the next time it is opened. I tried this but no luck. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; ComboBox(event.target).selectedItem.label; } Really appreciate the help Dan Pride
RE: [flexcoders] ComboBox in Component won't open to Saved Value
This seems absurdly difficult for so simple a function. I am trying to save a value from a popup and get it back when the list is double clicked and the form is represented with a different record selected. Not exactly rocket science. I have tried every single event and nada. Is there an on Load Why not? It seems so obvious. Creation complete only works the first time the form component is presented. The functions are private function closeRolePop(event:Event):void { ComboBox(event.target).selectedItem.label}; private function openRolePop(event:Event):void { var i:uint; for(i=0; i arrRoles.length; i++){ if(arrRoles.getItemAt(i).label == currentPerson.Role){ rolePop.selectedIndex = i; }}} Help Please this is really getting to me cause it should be so simple --- On Wed, 10/8/08, Dan Pride [EMAIL PROTECTED] wrote: From: Dan Pride [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 12:38 PM Creation complete works the first time but the component is displayed when you click on a list, and subsequent selections are not displayed. I am having trouble figuring out which on is the correct event.? Sorry but I am relatively new at this kind of programming. Thanks Dan --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] wrote: From: Tracy Spratt [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 11:34 AM Why are you doing that in the open event? Try creationComplete instead. Or set it directly without the function. Or bind selectedIndex to a bindable variable. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:57 AM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value Thanks for the response. I understand what needs to be done as you described but I still have one problem. I tried this before. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; } The ComboBox opened to the zero value not the 1. When I clicked on the box it opened to have the 1 value preselectect but did not present upon opening. I am referencing it like this and must be missing some kind of kick event? mx:ComboBox id=genderPop close=closeGenderPop(event) open=openGenderPop(event) dataProvider={arrGender} x=583.5 y=89 width=116 / Thanks again. This board is GREAT ! Dan Pride --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com wrote: From: Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Date: Wednesday, October 8, 2008, 11:05 AM ComboBox.selectedItem will only work if you assign a *reference to an item in the ComboBox dataProvider*. This is rarely possible and is not in your case. What you must do is loop over the items in the CobmoBox.dataProvider and compare the appropriate property's value to the value you want to match. When a match is found, use the loop indes to set the ComboBox's selectedIndex. This is simple enough to do in a one-off situation. If you need this often, then you might want to use an extended ComboBox. Making a generic one is a bit tricky, because the Combo Box dataProvider items can have any properties at all. I have an example on www.cflex.net http://www.cflex.net/ http://www.cflex.net/ (it allows you to set the data field you want to match) and Ben forta has done one and there are others. Tracy From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:01 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] ComboBox in Component won't open to Saved Value Hi I have a ComboBox used as a Popup on a form component. It saves fine using the following function private function closeGenderPop(event:Event):void { ComboBox(event.target).selectedItem.label}; I want to have it display the stored value the next time it is opened. I tried this but no luck. private function openGenderPop(event:Event
RE: [flexcoders] ComboBox in Component won't open to Saved Value
The Combobox by itself does not really support what you're trying to do. As Tracy said there is sample code you can draw on to extend the ComboBox to accept a 'selectedValue' parameter or something of the sort, which in turn will fire internal logic to determine which item in the dataProvider matches and to set the selectedIndex accordingly. The other part of this is using binding. To have your instantiated combobox to update its selectedIndex when a value changes you need to reference a bindable value. If another code alters that value, it will then re-fire the internal logic in your custom ComboBox. {Bindable] private var dp:Array = [{data:'foo',label:'foo'},{data:'foo1',label:'foo1'},{data:'foo2',label: 'foo2'}]; [Bindable] private var myVal:String = foo; local:CustomComboBox dataProvider={dp} selectedValue={myVal}/ Jeff -Original Message- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 1:23 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value This seems absurdly difficult for so simple a function. I am trying to save a value from a popup and get it back when the list is double clicked and the form is represented with a different record selected. Not exactly rocket science. I have tried every single event and nada. Is there an on Load Why not? It seems so obvious. Creation complete only works the first time the form component is presented. The functions are private function closeRolePop(event:Event):void { ComboBox(event.target).selectedItem.label}; private function openRolePop(event:Event):void { var i:uint; for(i=0; i arrRoles.length; i++){ if(arrRoles.getItemAt(i).label == currentPerson.Role){ rolePop.selectedIndex = i; }}} Help Please this is really getting to me cause it should be so simple --- On Wed, 10/8/08, Dan Pride [EMAIL PROTECTED] wrote: From: Dan Pride [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 12:38 PM Creation complete works the first time but the component is displayed when you click on a list, and subsequent selections are not displayed. I am having trouble figuring out which on is the correct event.? Sorry but I am relatively new at this kind of programming. Thanks Dan --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] wrote: From: Tracy Spratt [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 11:34 AM Why are you doing that in the open event? Try creationComplete instead. Or set it directly without the function. Or bind selectedIndex to a bindable variable. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:57 AM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value Thanks for the response. I understand what needs to be done as you described but I still have one problem. I tried this before. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; } The ComboBox opened to the zero value not the 1. When I clicked on the box it opened to have the 1 value preselectect but did not present upon opening. I am referencing it like this and must be missing some kind of kick event? mx:ComboBox id=genderPop close=closeGenderPop(event) open=openGenderPop(event) dataProvider={arrGender} x=583.5 y=89 width=116 / Thanks again. This board is GREAT ! Dan Pride --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com wrote: From: Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Date: Wednesday, October 8, 2008, 11:05 AM ComboBox.selectedItem will only work if you assign a *reference to an item in the ComboBox dataProvider*. This is rarely possible and is not in your case. What you must do is loop over the items in the CobmoBox.dataProvider and compare the appropriate property's value to the value you want to match. When a match is found, use the loop indes to set the ComboBox's selectedIndex. This is simple enough to do in a one-off situation. If you need this often, then you might want to use an extended ComboBox. Making a generic one is a bit tricky, because the Combo Box dataProvider
RE: [flexcoders] ComboBox in Component won't open to Saved Value
Am I going down the wrong road with ComboBox? Geez I can set a popup and get the value back with Php or any of a number of other languages. Seems REALLY absurd that this is this difficult. Dan P.S. Where do I get the custom combobox code? or will the binding approach work with a regular out of the box combobox? thanks for you time. --- On Wed, 10/8/08, Battershall, Jeff [EMAIL PROTECTED] wrote: From: Battershall, Jeff [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 1:38 PM The Combobox by itself does not really support what you're trying to do. As Tracy said there is sample code you can draw on to extend the ComboBox to accept a 'selectedValue' parameter or something of the sort, which in turn will fire internal logic to determine which item in the dataProvider matches and to set the selectedIndex accordingly. The other part of this is using binding. To have your instantiated combobox to update its selectedIndex when a value changes you need to reference a bindable value. If another code alters that value, it will then re-fire the internal logic in your custom ComboBox. {Bindable] private var dp:Array = [{data:'foo',label:'foo'},{data:'foo1',label:'foo1'},{data:'foo2',label: 'foo2'}]; [Bindable] private var myVal:String = foo; local:CustomComboBox dataProvider={dp} selectedValue={myVal}/ Jeff -Original Message- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 1:23 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value This seems absurdly difficult for so simple a function. I am trying to save a value from a popup and get it back when the list is double clicked and the form is represented with a different record selected. Not exactly rocket science. I have tried every single event and nada. Is there an on Load Why not? It seems so obvious. Creation complete only works the first time the form component is presented. The functions are private function closeRolePop(event:Event):void { ComboBox(event.target).selectedItem.label}; private function openRolePop(event:Event):void { var i:uint; for(i=0; i arrRoles.length; i++){ if(arrRoles.getItemAt(i).label == currentPerson.Role){ rolePop.selectedIndex = i; }}} Help Please this is really getting to me cause it should be so simple --- On Wed, 10/8/08, Dan Pride [EMAIL PROTECTED] wrote: From: Dan Pride [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 12:38 PM Creation complete works the first time but the component is displayed when you click on a list, and subsequent selections are not displayed. I am having trouble figuring out which on is the correct event.? Sorry but I am relatively new at this kind of programming. Thanks Dan --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] wrote: From: Tracy Spratt [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 11:34 AM Why are you doing that in the open event? Try creationComplete instead. Or set it directly without the function. Or bind selectedIndex to a bindable variable. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:57 AM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value Thanks for the response. I understand what needs to be done as you described but I still have one problem. I tried this before. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; } The ComboBox opened to the zero value not the 1. When I clicked on the box it opened to have the 1 value preselectect but did not present upon opening. I am referencing it like this and must be missing some kind of kick event? mx:ComboBox id=genderPop close=closeGenderPop(event) open=openGenderPop(event) dataProvider={arrGender} x=583.5 y=89 width=116 / Thanks again. This board is GREAT ! Dan Pride --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com wrote: From: Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com Subject: RE: [flexcoders] ComboBox in Component won't open
Re: [flexcoders] ComboBox in Component won't open to Saved Value
On Wed, Oct 8, 2008 at 2:04 PM, Dan Pride [EMAIL PROTECTED] wrote: Geez I can set a popup and get the value back with Php or any of a number of other languages. Seems REALLY absurd that this is this difficult. Different things are difficult in different languages. That's why they evolve, to make those difficult things easier and impossible things merely difficult. -- Howard Fore, [EMAIL PROTECTED] The universe tends toward maximum irony. Don't push it. - Jeff Atwood
RE: [flexcoders] ComboBox in Component won't open to Saved Value
The Combobox by itself does not really support what you're trying to do. Are you telling me that there is no simply way to have a user pick a value from a popup then redisplay that value in the popup if he goes back to the record again later? Is this a joke or a programing language? Somebody forgot to include an event that says if this record has a value show it in the popup? No you got to be pulling my chain. If you are not then this is a useless joke. Its an everyday need. Dan Pride --- On Wed, 10/8/08, Battershall, Jeff [EMAIL PROTECTED] wrote: From: Battershall, Jeff [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 1:38 PM The Combobox by itself does not really support what you're trying to do. As Tracy said there is sample code you can draw on to extend the ComboBox to accept a 'selectedValue' parameter or something of the sort, which in turn will fire internal logic to determine which item in the dataProvider matches and to set the selectedIndex accordingly. The other part of this is using binding. To have your instantiated combobox to update its selectedIndex when a value changes you need to reference a bindable value. If another code alters that value, it will then re-fire the internal logic in your custom ComboBox. {Bindable] private var dp:Array = [{data:'foo',label:'foo'},{data:'foo1',label:'foo1'},{data:'foo2',label: 'foo2'}]; [Bindable] private var myVal:String = foo; local:CustomComboBox dataProvider={dp} selectedValue={myVal}/ Jeff -Original Message- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 1:23 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value This seems absurdly difficult for so simple a function. I am trying to save a value from a popup and get it back when the list is double clicked and the form is represented with a different record selected. Not exactly rocket science. I have tried every single event and nada. Is there an on Load Why not? It seems so obvious. Creation complete only works the first time the form component is presented. The functions are private function closeRolePop(event:Event):void { ComboBox(event.target).selectedItem.label}; private function openRolePop(event:Event):void { var i:uint; for(i=0; i arrRoles.length; i++){ if(arrRoles.getItemAt(i).label == currentPerson.Role){ rolePop.selectedIndex = i; }}} Help Please this is really getting to me cause it should be so simple --- On Wed, 10/8/08, Dan Pride [EMAIL PROTECTED] wrote: From: Dan Pride [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 12:38 PM Creation complete works the first time but the component is displayed when you click on a list, and subsequent selections are not displayed. I am having trouble figuring out which on is the correct event.? Sorry but I am relatively new at this kind of programming. Thanks Dan --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] wrote: From: Tracy Spratt [EMAIL PROTECTED] Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com Date: Wednesday, October 8, 2008, 11:34 AM Why are you doing that in the open event? Try creationComplete instead. Or set it directly without the function. Or bind selectedIndex to a bindable variable. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 10:57 AM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value Thanks for the response. I understand what needs to be done as you described but I still have one problem. I tried this before. private function openGenderPop(event:Event):void { genderPop.selectedIndex = 1; } The ComboBox opened to the zero value not the 1. When I clicked on the box it opened to have the 1 value preselectect but did not present upon opening. I am referencing it like this and must be missing some kind of kick event? mx:ComboBox id=genderPop close=closeGenderPop(event) open=openGenderPop(event) dataProvider={arrGender} x=583.5 y=89 width=116 / Thanks again. This board is GREAT ! Dan Pride --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] mailto:tspratt
RE: [flexcoders] ComboBox in Component won't open to Saved Value
Depends on what you mean by simple. It will just take a few lines of code. The difficulty lies in knowing which lines. Going ballistic in frustration is never helpful. Take this one step at a time. Make sure you can call your function when the pop-up opens. Make sure you have the value you want to set the combo box to at that point. You have not shown us much code, so we can't really say what is wrong. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 4:49 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value The Combobox by itself does not really support what you're trying to do. Are you telling me that there is no simply way to have a user pick a value from a popup then redisplay that value in the popup if he goes back to the record again later? Is this a joke or a programing language? Somebody forgot to include an event that says if this record has a value show it in the popup? No you got to be pulling my chain. If you are not then this is a useless joke. Its an everyday need. Dan Pride --- On Wed, 10/8/08, Battershall, Jeff [EMAIL PROTECTED] mailto:jeff.battershall%40dowjones.com wrote: From: Battershall, Jeff [EMAIL PROTECTED] mailto:jeff.battershall%40dowjones.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Date: Wednesday, October 8, 2008, 1:38 PM The Combobox by itself does not really support what you're trying to do. As Tracy said there is sample code you can draw on to extend the ComboBox to accept a 'selectedValue' parameter or something of the sort, which in turn will fire internal logic to determine which item in the dataProvider matches and to set the selectedIndex accordingly. The other part of this is using binding. To have your instantiated combobox to update its selectedIndex when a value changes you need to reference a bindable value. If another code alters that value, it will then re-fire the internal logic in your custom ComboBox. {Bindable] private var dp:Array = [{data:'foo',label:'foo'},{data:'foo1',label:'foo1'},{data:'foo2',label: 'foo2'}]; [Bindable] private var myVal:String = foo; local:CustomComboBox dataProvider={dp} selectedValue={myVal}/ Jeff -Original Message- From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of Dan Pride Sent: Wednesday, October 08, 2008 1:23 PM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value This seems absurdly difficult for so simple a function. I am trying to save a value from a popup and get it back when the list is double clicked and the form is represented with a different record selected. Not exactly rocket science. I have tried every single event and nada. Is there an on Load Why not? It seems so obvious. Creation complete only works the first time the form component is presented. The functions are private function closeRolePop(event:Event):void { ComboBox(event.target).selectedItem.label}; private function openRolePop(event:Event):void { var i:uint; for(i=0; i arrRoles.length; i++){ if(arrRoles.getItemAt(i).label == currentPerson.Role){ rolePop.selectedIndex = i; }}} Help Please this is really getting to me cause it should be so simple --- On Wed, 10/8/08, Dan Pride [EMAIL PROTECTED] mailto:danielpride%40yahoo.com wrote: From: Dan Pride [EMAIL PROTECTED] mailto:danielpride%40yahoo.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Date: Wednesday, October 8, 2008, 12:38 PM Creation complete works the first time but the component is displayed when you click on a list, and subsequent selections are not displayed. I am having trouble figuring out which on is the correct event.? Sorry but I am relatively new at this kind of programming. Thanks Dan --- On Wed, 10/8/08, Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com wrote: From: Tracy Spratt [EMAIL PROTECTED] mailto:tspratt%40lariatinc.com Subject: RE: [flexcoders] ComboBox in Component won't open to Saved Value To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Date: Wednesday, October 8, 2008, 11:34 AM Why are you doing that in the open event? Try creationComplete instead. Or set it directly without the function. Or bind selectedIndex to a bindable variable. Tracy From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com