2 Replies Latest reply on Jun 3, 2008 3:39 PM by arav5566

    Regarding Dropdown box

    arav5566
      I created a dropdown box using flex3 builder. I want the dropdown to be populated with a different set of
      value when a button is clicked. how can i do it? Is there any good web links that shows some sample code to change the values dynamically in a dropdown box?
        • 1. Re: Regarding Dropdown box
          Gregory Lafrance Level 6
          This code is a bit wierd, but it works:

          <?xml version="1.0"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
          initialize="initData();">
          <mx:Script>
          <![CDATA[
          import mx.collections.*
          private var statesArr:Array=
          [{label:"MA", data:"Massachusetts"},
          {label:"CA", data:"California"},
          {label:"FL", data:"Florida"}];

          [Bindable]
          public var statesAC:ArrayCollection;

          private var dogsArr:Array=
          [{label:"TR", data:"Terrier"},
          {label:"GS", data:"German Shepard"},
          {label:"PD", data:"Poodle"}];

          [Bindable]
          public var dogsAC:ArrayCollection;

          private function initData():void {
          statesAC=new ArrayCollection(statesArr);
          dogsAC=new ArrayCollection(dogsArr);
          }

          private function clickHandler():void {
          if(cbx.dataProvider == statesAC){
          cbx.dataProvider = dogsAC;
          }
          else{
          cbx.dataProvider = statesAC; }
          }
          ]]>
          </mx:Script>

          <mx:ComboBox id="cbx" dataProvider="{statesAC}"/>
          <mx:Button label="Switch Data" click="clickHandler()"/>
          </mx:Application>
          • 2. Re: Regarding Dropdown box
            arav5566 Level 1
            Thanks for the info.
            > Is the initData() is called automatically or i need to call it some where?
            >How in flex3 garbage collection works? If i do the below one will it cause a memory leak of array collection holded by statesAC variable?
            private function initData():void {
            statesAC=new ArrayCollection(statesArr);
            dogsAC=new ArrayCollection(dogsArr);
            dogsAC=statesAC
            }