double click causes click-event and doubleClick-event

double click causes click-event and doubleClick-event

Post by jpsouther » Wed, 09 Apr 2008 03:23:14

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.

 
 
 

double click causes click-event and doubleClick-event

Post by sullet » Wed, 16 Apr 2008 06:27:46

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
}