3 Replies Latest reply on Nov 2, 2007 3:06 PM by Newsgroup_User

    Combo Box Component

    fermp Level 1
      Hi all,

      I am trying to figure out how to put a comboBox in my Flash form and normally I just use something like:

      countryList.dataProvider = ["Country1", "Country2", "Country3", "Country4"];

      var listenerObject:Object = new Object();
      listenerObject.change = function(evtObj:Object) {
      // code placed here executes
      // when the event is triggered
      trace("Selected Item: "+countryList.selectedItem);
      };
      countryList.addEventListener("change",listenerObject);

      This will give me the selected item's value which I can chuck in a variable and send off to my form...

      Well that is usually good enough but now I want to have a Label AND a Value so that when the user does the drop down they see the Label but I am actually sending the Value. I am messing around with the Flash Help code and I kind of see how this is working yet I can not get at the data I need which is the Value not the Label.

      my_cb.dataProvider = [{name:"Gary", gender:"male"}, {name:"Susan", gender:"female"}];
      my_cb.labelField = "name";

      var listenerObject:Object = new Object();
      listenerObject.change = function(evtObj:Object) {
      // code placed here executes
      // when the event is triggered
      trace("Selected Item: "+my_cb.selectedItem);
      };
      my_cb.addEventListener("change",listenerObject);

      Any help on this would be greatly appreciated.
        • 1. Re: Combo Box Component
          Level 7
          > var listenerObject:Object = new Object();
          > listenerObject.change = function(evtObj:Object) {
          > // code placed here executes
          > // when the event is triggered
          > trace("Selected Item: "+my_cb.selectedItem);
          > };
          > my_cb.addEventListener("change",listenerObject);

          trace("Selected Item Data: "+my_cb.selectedItem.data);
          trace("Selected Item Label: "+my_cb.selectedItem.label);

          hth


          --
          Dan Smith > adobe community expert
          http://www.dsmith.tv


          • 2. Re: Combo Box Component
            fermp Level 1
            Hi Dan,

            When I use this code I get:

            Selected Item Data: undefined
            Selected Item Label: undefined

            You would think there was something easy to allow for a label being different from the variable I'm sending. All I want to do is make the drop down menu say "Afghanistan" while I am sending the form data "AF" to the .php script that will save the data to a mySQl database. I can easily send the name of the country (Afghanistan) as thats the name of my_cb.selectedItem. I'm just not sure why it is so difficult to send the value (AF) instead. I'm just not getting it.
            • 3. Re: Combo Box Component
              Level 7
              > You would think there was something easy to allow for a label being
              > different
              > from the variable I'm sending. All I want to do is make the drop down menu
              > say
              > "Afghanistan" while I am sending the form data "AF" to the .php script
              > that
              > will save the data to a mySQl database. I can easily send the name of the
              > country (Afghanistan) as thats the name of my_cb.selectedItem. I'm just
              > not
              > sure why it is so difficult to send the value (AF) instead. I'm just not
              > getting it.

              Did you put the code I supplied in the event handler?

              var listenerObject:Object = new Object();
              listenerObject.change = function(evtObj:Object) {
              // code placed here executes
              // when the event is triggered
              trace("Selected Item Data: "+my_cb.selectedItem.data); //Put code here
              };

              --
              Dan Smith > adobe community expert
              http://www.dsmith.tv