1 Reply Latest reply on Jul 29, 2009 4:55 AM by _Natasha_

    How to restrict firing multiple events from combobox

    SirajKhan Level 1

      Hi There,

       

      I am using a customized combobox which allows me to select multiple indices. It is working fairly okay, except that it is firing multiple "change" events on updating combobox selection; all I need is, when combobox selection state is updated, it should fire single change event.

       

      here's the code:

       

      package
      {
          import flash.events.Event;
          import flash.events.KeyboardEvent;
          import mx.controls.ComboBox;
          import mx.events.FlexEvent;
          import mx.events.ListEvent;
          public class ComboBoxs extends ComboBox
          {

       

              public function ComboBoxs()
              {
                  super();
              }

       

              private var ctrlKey:Boolean=false;

       

              override public function close(trigger:Event=null):void
              {
                  if (!ctrlKey)
                      super.close(trigger);
              }

       

              [Bindable("change")]
              public function get selectedIndices():Array
              {
                  if (dropdown)
                      return dropdown.selectedIndices;

       

                  else
                      return null;
              }

       

              public function set selectedIndices(value:Array):void

       

              {
                  if (dropdown)
                      dropdown.selectedIndices=value;

       

              }

       

              [Bindable("change")]
              public function get selectedItems():Array

       

              {
                  if (dropdown)
                      return dropdown.selectedItems;

       

                  else
                      return null;
              }

       

              public function set selectedItems(value:Array):void

       

              {
                  if (dropdown)
                      dropdown.selectedItems=value;

       

              }

       

              override protected function keyDownHandler(event:KeyboardEvent):void
              {
                  super.keyDownHandler(event);
                  ctrlKey=event.ctrlKey;

       

                  if (ctrlKey)
                      dropdown.allowMultipleSelection=true;
              }

       

              override protected function keyUpHandler(event:KeyboardEvent):void
              {
                  super.keyUpHandler(event);
                  ctrlKey=event.ctrlKey;

       

                  if (!ctrlKey)
                  {
                      close();
                      var changeEvent:ListEvent=new ListEvent(ListEvent.CHANGE)
                      dispatchEvent(changeEvent);
                  }
              }
          }
      }

       

      Thanks in advance,

      Siraj Khan

      khan_siraj@yahoo.com