5 Replies Latest reply on Dec 12, 2006 2:44 PM by FlightGuy

    ComboBox Value

    jfillman Level 1
      I am attempting to capture the data value of the selected value of the ComboBox to send to a remote object, I just can't get the sytax right for referencing this.

      <mx:ComboBox dataProvider="{sleep}" width="150" close="selectedItem=ComboBox(event.target).selectedItem" id="ptSleep" top="250" left="165"/>

      public var sleep: Array = [ {label:"-", data:0}, {label:"1 Hour", data:1}, {label:"2 Hours", data:2}, {label:"3 Hours", data:3}, {label:"4 Hours", data:4}, {label:"5 Hours", data:5}, {label:"6 Hours", data:6}, {label:"7 Hours", data:7}, {label:"8 Hours", data:8}, {label:"9 Hours", data:9}, {label:"10 Hours", data:10}, {label:"11 Hours", data:11}, {label:"12 Hours", data:12}, {label:"13 Hours", data:13}, {label:"14 Hours", data:14}, {label:"15 Hours", data:15},{label:"15 Hours", data:15}, {label:"16 Hours", data:16},{label:"17 Hours", data:17}, {label:"18 Hours", data:18}, {label:"19 Hours", data:19}, {label:"20 Hours", data:20}, {label:"21 Hours", data:21}, {label:"22 Hours", data:22}, {label:"23 Hours", data:23}, {label:"24 Hours", data:24} ];

      public var selectedItem:Object;
        • 1. Re: ComboBox Value
          chris.huston.t10 Level 3
          It seems like you do not need your selectedItem variable since this is stored in the ComboBox object. So you can reference the selected value with:


          You can test this out with this code:
          <mx:ComboBox dataProvider="{sleep}" width="150" close="show_selected()" id="ptSleep" top="250" left="165"/>

          private function show_selected():void {

          If you want to access the label value then it is just:

          • 2. Re: ComboBox Value
            ntsiii Level 3
            And avoid using the same name for your variables or functions that Flex uses for its, like selectedItem. That is asking for very subtle problems.

            • 3. Re: ComboBox Value
              jfillman Level 1
              Thanks Masamune. I swore I tried that 10 times and it didn't work, but it works fine now.

              Tracy, I got one of those subtle little errors last night. Thanks for the heads-up.
              • 4. Re: ComboBox Value
                ntsiii Level 3
                "tried that 10 times... " Yep, sometimes, you just have to make the dang machine understand that you won't take "no" for an answer. ;)
                • 5. Re: ComboBox Value
                  FlightGuy Level 1
                  Just a little comment here: Don't be scared of the debugger - it's your friend. If you were to place a breakpoint on the line that assigns the selectedItem, you would be able to drill down into the event, to the selected Item, and you would see that it has a property "data".