Hi


I've encountered a situation in which I had to provide both click,
dbl-click and drag for the same graphical element.



I'm kinda of new to flex so I'm not sure the solution here is the best 
- but it works…



In principal the solution handles both mouseDown and mouseDown events on
the object. In a MD event –just add a listener for mouseMove (for
drag). In a MU event thing are more complex:

1)      keep the current event time

2)      Remove the mouseMove event listener (it is not a drag...)

3)      Check vs. last MU event time if this is a Dbl click or click

a.       If it might be a click you will need to wait to setup a timer
that will wait for 1-2 seconds to fire the click.

b.      If it is a dbl click Remove the timer and do the Dbl-click
actions.



Attached is the code with Alert.show for each situation.:





public var KeepLastMouseUp:Number =0;

public var ticker:Timer = new Timer(1000,1);





public function mouseDownHandler(e:MouseEvent):void {



             KPIBox = e.currentTarget as Canvas;

             KPIBox.parent.setChildIndex(KPIBox,KPIsData.length-1);



                                     KPIBox.addEventListener
(MouseEvent.MOUSE_MOVE,mouseMoveHandler);



}





public function mouseUpHandler(e:MouseEvent):void {



KPIBox = e.currentTarget as Canvas;

KPIBox.parent.setChildIndex(KPIBox,KPIsData.length-1);



var dt:Date = new Date();

var tm:Number = dt.getTime();



KPIBox.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);

if ((tm - 1000 )>KeepLastMouseUp) { //regular click.

KeepLastMouseUp = tm;

ticker.addEventListener(TimerEvent.TIMER, runClick);

             ticker.start();

return

}



//dbl click identified

KeepLastMouseUp=0;

ticker.removeEventListener(TimerEvent.TIMER, ClickPressed);

Alert.show("Dbl Click");

}





public function ClickPressed (e:TimerEvent):void {

Alert.show("click");



}



public function mouseMoveHandler(e:MouseEvent):void{

KPIBox.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);

Alert.show("start move");

}





Reply via email to