2 Replies Latest reply on Nov 13, 2006 12:48 AM by iquaaani

    xml to combobox problem

    iquaaani Level 1
      I'm populating combobox from xml file, everything goes ok

      My case : i'm reading xml file which look like this

      <Upload>
      <palettes>
      <pal30 name = "First map">
      <colors>map1.xml</colors>
      </pal30>
      <pal20 name = "Second map">
      <colors>map2.xml</colors>
      </pal20>
      </palettes>
      </Upload>

      by
      <mx:XML format="e4x" id="mapp" source="Database/Map.xml"/>
      <mx:ComboBox x="263" y="10" width="194"
      id="myCb" enabled="true"
      dataProvider="{mapp.Upload.palettes.*.@name}">
      </mx:ComboBox>

      So, what i'm trying to do is when i click "First map" from my combobox i want to have "map1.xml" 'printed' in a mx:Text control

      I can get the attribute name in text box by <mx:Text text="{myCb.selectedItem}"/> which could be in this case "First Map" and i want to have "map1.xml" when i click "First map" in combobox.

      Do i have to create some kind of array out of my xml file where the values are related together like
      {name:"First map", file:"map1.xml"}



        • 1. Re: xml to combobox problem
          peterent Level 2
          The problem is that your nodes are not consistently named. If you had <pal code="30"> and <pal code="20"> then you could set the dataProvider="{mapp.pal}" and labelField="@name" then the selectedItem.colors would be what you want.

          When you used the expression you created an Array of just the name values - there is no context any longer. Try this instead:

          <mx:ComboBox dataProvider="{mapp.palettes.*}" labelFunction="paletteName" change="test(event)" />

          In a Script block:

          private function paletteName( item:Object ) : String
          {
          return XML(item).@name;
          }

          private function test( event:Event ) : void
          {
          output.text = XML(event.target.selectedItem).colors;
          }

          Now the selectedItem will be the XML for a pal node so XML(selectedItem).colors will be map1.xml or map2.xml.
          • 2. Re: xml to combobox problem
            iquaaani Level 1
            Thansk for the answer :)