views:

938

answers:

5

I have 2 seperate events that are not related to each other and each is attached to the Mouseclick and Doubleclick eventresponses respectively. However, during runtime, I find that even when I doubleclick, the Mouseclick action still gets activated.

I've been trying to find a viable solution where the Mouseclick and Doubleclick can co-exist independent of each other but no luck so far. I've even tried having the mouseclick eventresponse wait for a few miliseconds before kicking off (so that it gives a chance for the user to doubleclick) but that is not the most efficient solution either.

Does anyone have any ideas? Or can point me to a place where I can get a much better understanding of how the Mouseclick and Doubleclick eventresponses are captured in flash?

I've been looking around but have not been able to find anything in depth enough that mentions how each of the eventresponses actually work.

+1  A: 

I think you will have to use a timer, it is the only way to differentiate between the two. There are some issues with the single-threaded event-driven nature of AS that you have to watch out for; I think I would implement it like this:

var timer:Timer = new Timer(100,1);
private function clickHandler(event:MouseEvent):void
{     
    timer.addEventListener(TimerEvent.TIMER, singleClickHandler);
    timer.start();
}

private function doubleClickHandler(event:MouseEvent):void
{
    timer.stop();
    ...
}

private function singleClickHandler(event:TimerEvent):void
{

}
CookieOfFortune
You can also use timer = "setTimeout(singleClickHAndler, 100); And then do a clearTimeout(timer) if you cancel it. Also make sure that your timer isn't a var local to the clickhandler function.
Glenn
Thanks for catching the bug, code edited.
CookieOfFortune
A: 

My experience is that this is at least partly by design. It can easily be pretty risky from a UI point of view. Users aren't necessarily adept at clicking quickly enough to provide you with the distinction in any case. And if they aren't sure they clicked properly, they may reclick too quickly for you to distinguish.

Think about what happens in any ol' application when you double-click (because I imagine this circumstance is not unusual). As I'm typing this right now, if I double-click elsewhere in the text, a word is selected and highlighted, and the cursor disappears; it may have been positioned after the first click, and then nullified by the double-click handler.

le dorfier
A: 

Because the doubleclick speed is set by the user, a timer might not work if the user has set the doubleclick rate very slow 1.

A workaround might be to implement your own doubleclick at two single clicks within 500 ms (the default timing in Windows).

Depending on what the first click does, you could just reverse the behavior of the first click. For example, if the first click makes the folder inverted color, then the second click could both open the folder and uninvert it.

A: 

No need to use timer. Just follow this

someMovieClip.doubleClickEnabled = true;

someMovieClip.addEventListener(MouseEvent.DOUBLE_CLICK, someFunction);

function someFunction(e:MouseEvent):void{

 someMovieClip.removeEventListener(MouseEvent.CLICK, clickFunction);

  // statement for double click action

}

Rajneesh
A: 

In this way you just kill the (wanted) click-event. And as he said, both handler doesn't know each other, so you cannot kill the handling for others, that's very bad practice.

For my understanding, he wants both. So "doubleClickEnabled" should result in a delayed clickEvent-handling, so it can be REPLACED by a doubleClick-event, if a second click occurs in meantime.

But it doesn't, both events will be triggered. This behaviour is unexpected - as soon "doubleClickEnabled" is enabled for an InteractiveObject, every single-click should have noticeable lag, because the doubleClick-handler still waits for a possible second click. If the time for waiting is over, a normal click-event is fired.

Still have the same problem and no slick solution for that.

Tomahawk