3 Replies Latest reply on Jul 17, 2006 7:32 PM by inlineblue

    Setting a ComboBox value

    Jim the Knife
      Hi,

      I've got an MXML which populates its dropdowns via a webservice. That all works fine. The issue that I face now is that I allow the parent ASPX application to pass FlashVars to the MXML, and I would like to use those parameters to set the value of the various dropdowns. The ComboBox.value property is read-only, and I can't provide an object to SelectedItem, as far as I can tell. I know I can iterate through the ComboBox items and set the SelectedIndex once I get to the right item, but that's stupid and inefficient. Is there a straightforward way to do this?

      Thanks!
        • 1. Re: Setting a ComboBox value
          matthisamoto
          are you using equal signs when you are referring to the combobox.value? if so you need a double equals: ==

          if not, im not sure what to tell you :\

          hope this helps
          • 2. Re: Setting a ComboBox value
            Jim the Knife Level 1
            Well, that's the point - I *do* want to set the value. Here's the code I'm trying to optimize:

            var locationID:int = int(Application.application.parameters.locationID);
            for(var i:int = 0; i < aLocation.length; i++)
            {
            if(aLocation .LocationID == locationID)
            {
            cmbCenter.selectedIndex = i;
            break;
            }
            }
            It just seems like it should be possible to set this value with a single statement, e.g.
            cmbCenter.value = 22; //or whatever
            • 3. Re: Setting a ComboBox value
              inlineblue Level 1
              Honestly, there is no better way to do this. The items are stored in a linear list and not sorted in any way. The only algorithm for this is a linear search. And don't think that setting selectedItem is any better--the combobox does a linear search to find a match. The rationale here is that the number of items in a combobox is typically small (a dozen or less, perhaps). Any solution more complex is simply over-engineering.