Combobox data issue

770
7
08-05-2010 06:57 AM
CaseyBentz
Occasional Contributor II
I have two comboboxes using data gathered from a httpService call.  One with region and one with teams from that region.  So that when you change the region you get a new list of teams.  Seems simple enough

When it loads initially I get the proper results.  When I change the area the first time I get the proper results, except the combobox size shrinks up to only show two of the results.  When I change the area again I see the first team in the display of the combobox until I click on the drop down and it still shows the old results. If I click one of the old results, it then shows the new list.  I have torn this part of my design down and completely rebuilt it a half dozen times, and I get the same results every time.

I am using this example as a guide...http://blog.flexexamples.com/2007/08/04/creating-two-related-comboboxes/

//Here is my code
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="loadAreas()">
 <mx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   import com.model.Model;
   
   public function loadAreas():void{
    var ac:ArrayCollection = new ArrayCollection();
    for each(var area:Object in Model.instance.vehicleAC){
     ac.addItem({name: area.name, children: area.children});
    }
    areaCB.dataProvider = ac;
   }
   private function areaChange():void{
    teamCB.dataProvider = null;
    teamCB.dataProvider = areaCB.selectedItem.children;
   }
  ]]>
 </mx:Script>
 <mx:ComboBox id="areaCB" labelField="name" change="areaChange()"/>
 <mx:ComboBox id="teamCB" dataProvider="{areaCB.selectedItem.children}" labelField="Team"/>
</mx:HBox>
Tags (2)
0 Kudos
7 Replies
ReneRubalcava
Frequent Contributor
You can try calling areaChange on the close event, but I think the issue might be that since you have combobox 2 bound to an object in the selected item of combobox 1, you don't need to make the function call at all. Try removing the areaChange call where you set the dataProvider to null. You shouldn't need it.
0 Kudos
CaseyBentz
Occasional Contributor II
I actually added the areaChange function because it wasn't working as expected.  I removed it for clarity.

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="loadAreas()">
 <mx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   import com.model.Model;
   
   public function loadAreas():void{
    var ac:ArrayCollection = new ArrayCollection();
    for each(var area:Object in Model.instance.vehicleAC){
     ac.addItem({name: area.name, children: area.children});
    }
    areaCB.dataProvider = ac;
   }
  ]]>
 </mx:Script>
 <mx:ComboBox id="areaCB" labelField="name"/>
 <mx:ComboBox id="teamCB" dataProvider="{areaCB.selectedItem.children}" labelField="Team"/>
</mx:HBox>
0 Kudos
CaseyBentz
Occasional Contributor II
I actually copied the code from the sample I included in my first post into my project and I get the same results.  The sample is using the 2.0 SDK of Flex, while I am using 3.5.  Anyone think this could be the issue, or has anyone seen a 3.5 version like this?
0 Kudos
ReneRubalcava
Frequent Contributor
Hi Casey,
There is a similar case noted on the Adobe forums with syncing ComboBoxes using SDK 3.5
I can repeat the bug in this thread in the 3.5 SDK that ships with FlashBuilder 4.
http://forums.adobe.com/message/2642802

It may be related. Can you provide a sample of the ArrayCollection? I think I still have some nightly builds I can test against.
0 Kudos
CaseyBentz
Occasional Contributor II
I don't relly know how I could get you the array collection.  I take a httpService result and configure it the way I need it then I loop through it and create a custom object...However, using the xml file from the sample, I was able to get the same behavior.  I tried to the 3.4 SDK and it works there.
0 Kudos
ReneRubalcava
Frequent Contributor
I tried your code using Flex 3.6 nightly build and it worked fine. So the issue appears to be a 3.5 bug.
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">
 <mx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   
   [Bindable]
   protected var ac:ArrayCollection = new ArrayCollection([{name:"Bob",
                  children:["bobby", "sally", "billy"]},
                 {name:"Sarah",
                  children:["angie","kelly"]},
                 {name:"Sam",
                  children:["sammy","roger","troy", "rich"]}]);
  ]]>
 </mx:Script>
 <mx:ComboBox id="areaCB"
     labelField="name"
     dataProvider="{ac}" />
 <mx:ComboBox id="teamCB"
     dataProvider="{areaCB.selectedItem.children}"
     labelField="Team" />
</mx:HBox>


You're best bet is to either downgrade to 3.4 or move to 3.6.
0 Kudos
CaseyBentz
Occasional Contributor II
Is the 3.6 version available as a production release? Is see this information posted on Adobe's website...Flex SDK version 3.5.0.12683a is the most recent update to the Flex 3 code-base.
0 Kudos