3 Replies Latest reply on Dec 28, 2008 10:08 AM by ntsiii

    populate combobox from xml

    cfortin14 Level 1
      I am trying to populate a combobox with data from an xml file, this is supposed to be a simple straight forward deal, but for some reason I cannot make it work. This is what I am doing:

        • 1. Re: populate combobox from xml
          cfortin14 Level 1
          I found a solution!

          I do not understand the logic behind it, but it works!

          I removed the dataProvider="{cbData}" and labelField="@label" attributes from the <mx:ComboBox and I moved the code to the HTTPService result handler, the function now looks like this:

          private function lookUpDataHandler(evt:ResultEvent):void {
          denomination.labelField = 'label';
          denomination.dataProvider = evt.result.allrows.singlerow;

          I someone can explain the reason why the previous code does not work, please do so.
          • 2. Re: populate combobox from xml
            rtalton Level 4
            Hey there,
            To make this really simple, here's what you could do:
            prompt="Please Select an Option..."
            dataProvider="{lookUpData.lastResult.allrows.singlerow}" />
            1) You assign the HTTPService' lastResult directly to the dataProvider of the comboBox.
            2) There is no need to specify the labelField, as your xml data file already has a "label" node. Only specify this if you do NOT have a node named "label", which the comboBox expects to find by default if using objects as the data source.
            • 3. Re: populate combobox from xml
              ntsiii Level 3
              And the reason you code failed before was because you did not set the resultFormat="e4x". thus your result data was a tree of dynamic objects, not xml, and the xml expressions (like @label) would fail.

              I advise changing that resultFormat and going back to your original code.

              I also advise against binding to lastResult because it is hard to debug and does not permit you to process the data in any way you might need.

              Note, comboBox will default to "label" as the labelField.