set selected item of combobox

Hi,

what is the best way to set the selected item of a combobox when i only have the data that i want to be selected?

thanks - Trevor
LVL 8
trevorhartmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

befidledCommented:
What exactly are you trying to do? There are a couple of ways to set the data within a combo box. One is to dynamically retrieve the data from an external source (i.e. XML file or database) while the other is to hard code the data directly by editing the "labels" in the Parameters tab of the properties toolbar.

Does that help at all?

Brian Fidler
0
trevorhartmanAuthor Commented:
I don't mean set the data, or give it a data source, or populate the combobox.

let's say I have a prepopulated combobox.  All data was set in flash by me.  Now in actoinscript i dynamically want to tell it to select the item whose value is "x"

whats the best way?


thx - Trevor
0
blue-genieCommented:
Hi Trevor,

here's an option.

use an array to store all your data values for your combobox.
then using a function, return the index (i.e location in array) of that value.

since both the combobox index and array index are 0 based (i.e. start at 0) , you then know which item to select.

in other words.
in your main timeline... //myBox_cb being the instance name of the cb

Array.prototype.getIndex = function(data) {
      for (i=0; i<this.length; ++i) {
            if (this[i] == data) {
                  return i;
            }
      }
      return -1;
};
boxData = new Array("1", "2", "3"); //put your data values here
location = boxData.getIndex("2"); //specify which is the item you want selected
myBox_cb.setSelectedIndex(location);

ps. based and tested on Flash UI Components 1 (flash mx).

blu.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
trevorhartmanAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.