2 Replies Latest reply on Apr 14, 2008 2:27 PM by sulletf

    double click causes click-event and doubleClick-event

    haku63
      When I define click- and doubleClick- (or itemClick-/itemDoubleClick-) event handlers for e.g. a mx:Tree, the single click is handled properly. When I try a double click, I always get first the click- and then the doubleClick-handler called.
      Am I missing something, is this a bug or a feature? :-)

      Harald
        • 1. Re: double click causes click-event and doubleClick-event
          jpsouthern
          I too am interested in a response to this. I see all kinds of information on how to enable the double-click event, but not how to distinguish during event handling. Here are the mouse events my UIComponent subclass gets:

          MOUSE_DOWN
          MOUSE_UP
          CLICK
          MOUSE_DOWN
          MOUSE_UP
          DOUBLE_CLICK

          In another interesting twist of events (play on words not intended), if I "handle" too much processing in the CLICK handler, then the DOUBLE_CLICK never fires. I suppose there's a timing problem with doing too much in the handler that keeps the DOUBLE_CLICK from happening.
          • 2. Re: double click causes click-event and doubleClick-event
            sulletf
            This is a normal feature in Flex.
            In order to be able to handle both click and doubleclick, i use a Timer object running during 300ms while mouse events are collected in an array.

            Once the timer stops, a 'timer' event is triggered ; by using an eventListener function, i check the event array : the last event added is the actual event to process by my application.

            public var ctlClicks:Array = new Array();
            public var timerForMouseClicks:Timer = new Timer(300);
            ...
            timerForMouseClicks.addEventListener('timer', designModeMouseLauncher);
            ...

            public function designModeMouseCollector(event:MouseEvent): void {

            switch ( event.type ) {

            case 'mouseDown':
            if ( !timerForMouseClicks.running ) { timerForMouseClicks.start() }
            case 'mouseUp':
            case 'click':
            case 'doubleClick':
            ctlClicks.push(event);
            break;
            default:
            designModeMouseHandler(event);
            break;
            }

            }

            ...
            public function designModeMouseLauncher(event:Event): void {

            timerForMouseClicks.stop();
            designModeMouseHandler( ctlClicks[ctlClicks.length-1] );
            ctlClicks.length=0;

            }

            ...

            public function designModeMouseHandler(event:MouseEvent): void {
            // your actual mouse event manager
            }