3 Replies Latest reply on Jan 24, 2008 10:38 AM by Greg Dove

    combo box not registering first selection

    Level 7
      Could someone please take a look at the code below and let me know why when
      this is first encountered it does not trace when the first item in the list
      is selected. If you select another item, it traces, and then select the
      first item, it traces.

      But when you select the first item (before anything else has happened) it
      does not trace. This must be a bug, is there a workaround?

      Please could anyone help, would really appreciate the input.

      import mx.controls.ComboBox;
      createClassObject(ComboBox,"cbTREATMENT",5,{_x:100,_y:100,fontSize:"13",color:"0x000000",f ontWeight:"bold",fontFamily:"arial",rowHeight:30});

      vTREATMENT="item2";

      cbTREATMENT.dropdown.rowHeight = 18;
      cbTREATMENT.dataProvider=["","item1","item2","item3"];
      cbTREATMENT.text=vTREATMENT;

      var listenerObject:Object = new Object();
      listenerObject.change = function(eventObject:Object) {
      trace("Selected item="+cbTREATMENT.text);
      }
      cbTREATMENT.addEventListener("change", listenerObject)


        • 1. Re: combo box not registering first selection
          Greg Dove Level 4
          I believe it was because the selectedIndex was still 0 (the first item in the list). But that you had just changed the text being displayed in the component (which does not change the index that is selected inside the component, just what is displayed in its text field). This seems to be correct behaviour for the text property of the Combobox. What does not seem to be correct is that you can set the text property. It is supposed to be only able to be set when the editable property is true. I was able to make your code work as original even after explicitly setting editable to false.

          Either way, here's what I would do:
          • 2. Re: combo box not registering first selection
            Level 7
            Thanks for this, that has certainly solved that issue!

            "GWD" <webforumsuser@macromedia.com> wrote in message
            news:fna5dk$59g$1@forums.macromedia.com...
            >I believe it was because the selectedIndex was still 0 (the first item in
            >the
            > list). But that you had just changed the text being displayed in the
            > component
            > (which does not change the index that is selected inside the component,
            > just
            > what is displayed in its text field). This seems to be correct behaviour
            > for
            > the text property of the Combobox. What does not seem to be correct is
            > that
            > you can set the text property. It is supposed to be only able to be set
            > when
            > the editable property is true. I was able to make your code work as
            > original
            > even after explicitly setting editable to false.
            >
            > Either way, here's what I would do:
            >
            > import mx.controls.ComboBox;
            >
            > createClassObject(ComboBox,"cbTREATMENT",5,{_x:100,_y:100,fontSize:"13",color:"0
            > x000000",fontWeight:"bold",fontFamily:"arial",rowHeight:30});
            >
            > vTREATMENT="item2";
            >
            > cbTREATMENT.dropdown.rowHeight = 18;
            > cbTREATMENT.dataProvider=["","item1","item2","item3"];
            > //cbTREATMENT.text=vTREATMENT; <- this just sets the text in the display
            > to
            > "item2". The default selectedIndex was still 0 (empty string)
            > cbTREATMENT.selectedIndex=2;//to default to item2 <-now it behaves like
            > you'd expect
            > var listenerObject:Object = new Object();
            > listenerObject.change = function(eventObject:Object) {
            > trace("Selected item="+cbTREATMENT.text);
            > }
            > cbTREATMENT.addEventListener("change", listenerObject)
            >