5 Replies Latest reply on Jul 27, 2010 7:29 AM by gtbus

    Access the previously selected item on a comboBox?

    gtbus

      Is there a property in the comboBox component that reflects the previously selected item when a new one is selected; accessible, for example, from the events dispatched when a different one is selected from the dropdown (eg. Event.CHANGE or DropdownEvent.CLOSE events) ???

       

      Thanks!

      gtb

        • 1. Re: Access the previously selected item on a comboBox?
          gtbus Level 1

          No way to do this?


          • 2. Re: Access the previously selected item on a comboBox?
            Shongrunden Adobe Employee

            There should be an oldIndex property on the change event, for example:

             

            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark">
                <fx:Script>
                    <![CDATA[
                        import spark.events.IndexChangeEvent;

             

                        private function changeHandler(event:IndexChangeEvent):void {
                            trace("new selected index: "+event.newIndex);
                            trace("old selected index: "+event.oldIndex);
                        }

             

                    ]]>
                </fx:Script>

             

                <s:DropDownList id="ddl" change="changeHandler(event)">
                    <s:ArrayList>
                        <fx:String>one</fx:String>
                        <fx:String>two</fx:String>
                        <fx:String>three</fx:String>
                    </s:ArrayList>
                </s:DropDownList>
               
            </s:Application>

             

            Does that help?

            1 person found this helpful
            • 3. Re: Access the previously selected item on a comboBox?
              gtbus Level 1

              Thanks for your reply Shongrunden...

              Your solution applies for the Flex 4 framework, but how about for the Flex 3 framework?

              gtb!

              • 4. Re: Access the previously selected item on a comboBox?
                BhaskerChari Level 4

                Hi gtbus,

                 

                You can acheive this in Flex3 by using something as shown below:

                 

                var prevIndex:int;

                 

                //This function you need to call when the dataprovider to your combobox is binded

                private function onCreationComplete(event:Event):void

                {

                     prevIndex = comboBox.selectedIndex;

                }

                 

                // This is the chnage Handler function for your ComboBox

                private function comboBoxChangeHandler(event:Event):void

                {

                    prevIndex =  comboBox.selectedIndex;

                }

                 

                So your prevIndex holds the previous selected Index of the combobox..

                 

                If this post answers your question or helps, please kindly mark it as such.


                Thanks,

                Bhasker Chari

                1 person found this helpful
                • 5. Re: Access the previously selected item on a comboBox?
                  gtbus Level 1

                  What I did to solve this is, instead of calling myFunction() on DropdownEvent.CLOSE, I called anotherFunction() on DropdownEvent.OPEN; which stores the selectedItem on the combo and adds an eventListener (if not added) for the ListEvent.CHANGE to execute the original myFunction() on that event.

                   

                  Thanks all for the help,

                  Gtb