set selected item of combobox

Posted on 2004-11-16
Last Modified: 2007-12-19

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
Question by:trevorhartman
    LVL 1

    Expert Comment

    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
    LVL 8

    Author Comment

    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
    LVL 39

    Accepted Solution

    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

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

    LVL 8

    Author Comment


    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
    The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
    The goal of the tutorial is to teach the user how to how to record live broadcast.
    The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now