1 Reply Latest reply on Dec 20, 2010 4:16 AM by DavideBarranca

    Dynamic Combobox via XMLList

    gmitchel

      I want a dynamic Combobox. So I created an XMLList object and made it bindable.

       

      I searched several books, the Web, and this forum. None of the examples was exactly on point or worked. This code does work with Flex 3. I'm posting it to saveothers such a search

       

      [Bindable]
      private var LayerBlendList:XMLList;


      var Blends:XMLList;
      LayerBlends = new XMLList(<blends>
          <blend label="Normal" />
          <blend label="Luminosity" />
          <blend label="Darken" />
          <blend label="Lighten" />
          <blend label="Darker Color" />
          <blend label="Lighter Color" />
          </blends>);

       

      LayerBlendList = new XMLList(LayerBlends.blend.attributes());

       

      <mx:ComboBox x="58" y="10" id="ComboBlend" width="140" selectedIndex="0" fontSize="9" editable="false"
            dataProvider="{LayerBlendList}" labelField="label" change="changeComboBlend();"/>

       

      If you use more than one attribute, as I do below, substitute the attribute() property for attributes().

       

      Presets = new XMLList(<presets>
                <preset label="(Custom)" settings="" canDelete="false" />
                <preset label="Capture: Single" settings="300,0.8,0,1,65,30,50,100,195,25,50,80,200" canDelete="true" />
                <preset label="Capture: Darken" settings="300,0.8,0,2,65,30,50,70,70,25,50,70,70" canDelete="true" />
                <preset label="Capture: Lighten" settings="300,0.8,0,3,65,70,70,100,195,25,40,80,200" canDelete="true" />
                <preset label="Creative: Sharpen" settings="300,0.8,0,1,65,16,24,208,224,24,32,176,208" canDelete="true" />
                <preset label="Creative: LCE" settings="20,50,0,1,65,16,24,208,224,28,52,176,208" canDelete="true" />
                     </presets>);
      PresetList = new XMLList(Presets.preset.attribute("label"));

      This will populate the Combobox with the "label" attributes. Do not bother with the labelField property on the Combobox control. It appears to have no effect.

       

      I hope this helps. I'd like the couple of days of my life back being frustrated over trying different different code samples and different permutations with XML, XMLList, and XMLListCollection items to get this to work!

       

      Cheers,

       

      Mitch

        • 1. Re: Dynamic Combobox via XMLList
          DavideBarranca Level 1

          Thanks Mitch!

          I still have an annoying bug: in the first example I got errors ("Access of undefined property LayerBlendList" and "Access of undefined property LayerBlends"), while if I change the:

           

          [Bindable]
          private var LayerBlendList:XMLList;

          ...

          LayerBlendList = new XMLList(LayerBlends.blend.attributes());

           

          into one line:

           

          [Bindable]

          public var LayerBlendList:XMLList = new XMLList(LayerBlends.blend.attribute("label"));

           

          everything runs file.

          I really can't figure out the why... Any idea?

          Thanks,

           

          Davide