Double clic (Flash AS3)

I tested MouseEvent.DOUBLE_CLICK listener in AS3. It saves you from creating your own double click listener (and it’s quite useful).
However, it seems that you can use a simple click listener and a double click listener on the same object. When you “double click”, click event is identified on the first click, and double click event on the second.

You can either re-create a double click detection or put a ‘validator’ on simple click detection .
I choose the second solution, with a timer :

//clicks handling
private var isARealClick:Boolean = false;
private var clickTimer:Timer;
private var delay:uint = 500;
private var repeat:uint = 1;

public function Work():void
//enable double click
this.doubleClickEnabled = true;

this.addEventListener(MouseEvent.CLICK, click);
this.addEventListener(MouseEvent.DOUBLE_CLICK, doubleClick);

clickTimer = new Timer(delay, repeat);

/** simple click handling*/
private function click(evt:MouseEvent):void
trace(“click ?”);
trace(“fake click…”);
isARealClick = false;
clickTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerFinish);
trace(“true click ! “);
isARealClick = true;
clickTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerFinish);

/** double click handling */
private function doubleClick(evt:MouseEvent):void
trace(“double click !”);

public function timerFinish(event:TimerEvent):void
trace(“this is a true click ! “);

Leave a Reply

Your email address will not be published. Required fields are marked *