2 Replies Latest reply on Nov 15, 2012 8:12 AM by swremaily

    Need to detect when an item is clicked in a combo box in flex 3

    blossoms_bubbles

      Hello

       

      I am having a check box and a combo box whenever any selection is made in combo box (current selection may be same as previous selection), I need to select the check box.

       

      By default the 1st item in combo box is selected and check box is unselected. Now I want that while 1st item is clicked in combo box (although it is selected) , the check box must be selected.

       

      I have currently used the change event of combo box to do my task. But it is not working if I click on same item as selected item in combo box.

       

      Also, I thought to use close event of combo box, but that event dispatches in 4 situations out of which I can distinguish only 1 situation from DropDownEvent(for close).

       

      Please help me regarding this.

       

      I am using flex sdk 3.5

       

      Thanks in advance.

        • 1. Re: Need to detect when an item is clicked in a combo box in flex 3
          J Clow

          You can use the Close Event to distinguish it.

           

          To pull out which item has been selected in the combo box, you use the code (in as3)

           

           

          ComboBox(event.target).selectedItem.label
          

           

          and through the the use of an if statement


          if (ComboBox(event.target).selectedItem.label == "labelName")


          you can distinguish the single situation from the others.

          • 2. Re: Need to detect when an item is clicked in a combo box in flex 3
            swremaily

            The problem with using the close event as blossoms_bubbles mentions is that the dropdown can be closed in multiple ways (such as clicking anywhere off the combobox) and not simply as a result of an item click.

             

            You can use the combobox prompt property as a workaround for this using only the change event.

             

            When you init your combobox:

             

            combobox.prompt = combobox.selectedLabel;

            combobox.selectedIndex = -1;

             

            And your change event method:

             

            function comboChangeEventHandler(e:Event):void

            {

                 //perform your action using selectedIndex or selectedLabel as normal

             

                 //then

                 combobox.prompt = combobox.selectedLabel;

                 combobox.selectedIndex = -1;

             

            }

             

            In this way, the combobox will still display the selected label as it is supposed to by default, but all items in the drop down remain selectable, including the mischievous first item.