Skip to main content
December 5, 2007
Question

able to obtain double click time from actionscript?

  • December 5, 2007
  • 8 replies
  • 1766 views
Is it possible to obtain whatever system setting Flash is using to determine the length of time that is used to determine whether a double click mouse event is fired?

thanks.
This topic has been closed for replies.

8 replies

December 6, 2007
BSpero - yes that is what I'm currently doing. And the question is how long to set that timer for, which is why I was wondering if I could access the same time value that Flash is using.

Andrei1 - if that is what Flash is doing, that's not what I observed. I observed that the single click listener would always fire no matter what.
Inspiring
December 6, 2007
Even if you set enableDoubleClick = true?
Inspiring
December 6, 2007
jigidyjim,
I get what you're saying. You could add a timeOut object on the item that lasts for, say .5 seconds. If the object recieved a double click event, then the first timeout would be cleared, and another action would immediately be fired. You probably already have this solution and really just wanted a way to grab the timing from the system, but at any rate...

var clickTimeout

with (mcButton) {
doubleClickEnabled = true;
addEventListener(MouseEvent.DOUBLE_CLICK,doubleClick);
addEventListener(MouseEvent.CLICK,singleClick);
}

function doubleClick(e:Event):void {
clearTimeout(clickTimeout);
trace("double click");
}
//
function singleClick(e:Event):void {
clearTimeout(clickTimeout);
clickTimeout = setTimeout(showSingleClick,500);
}
//
function showSingleClick(){
trace("single click");
}
December 6, 2007
Sorry, I didn't explain totally correctly. I can use the double click mechanism, but the issue is that I need to know whether or not to fire off the single click event when it is received from the first click.

If I decide to wait until I do or do not receive a double click event, the issue then is how long do I need to wait? If I receive a double click it's easy - i know then not use the initial click event I received. But I don't receive a double click, then without knowing how long i need to wait, i never know if one is coming or not.
Inspiring
December 6, 2007
I am still contemplating the alternatives for the sake of theory of it but first I would like to state that based on what was able to find about double click in Flash it is safe to assume that click and double click are mutually exclusive and that your sprite will function as specified if you just use two listeners - one for click, another - for double click. Actually double click does exactly what you are trying to accomplish - it sort of has it own timer and waits for the specified by OS period and prevents single click listener from firing. If it doesn't receive the second click within this time period - it will release CLICK event and CLICK will fire. Otherwise - it will do what it is asked to and CLICK will never launch. Isn't it the same as you want?

But I am thinking, and thinking, and thinking.....
December 6, 2007
Sure - thanks for the help.

I have a sprite that, if clicked on once, has one effect, and if double clicked, has a different effect.

The idea is that only one effect should play, not both. So if the user clicks the sprite, a delay needs to happen before the sprite decides whether or not to activate the single-click effect, or the double-click effect.

The only way I've figured out how to do this is to detect single clicks, and queue them up. When a click happens, I start a timer. If the timer expires without a click, then I fire off the single click event. If a second click happens before the timer expires, I fire off the double click event.

So in this method, I'm not using the built in double click mechanism at all.

If there were a way to accomplish this same task while still using the normal Flash DOUBLE_CLICK, I'd love to know how that is done.
Inspiring
December 6, 2007
While I am contemplating an idea, could you explain again why you don't trust double click please? I mean why two listeners cannot be added to the same sprite? Did you confirm if the required functionality cannot be accomplished with two listeners?

Meanwhile I have to think about how to use event dispatcher model to accommodate the thing without double click.

December 6, 2007
How can you calculate it?

The whole point is that i can't use the built in flash double-click mechanism, because I need to have a mechanism that doesn't dispatch single-clicks until it knows whether or not a double click has occurred. in order to do this, I need to put a timer on when a single-click should expire.

The only way I see to calculate it is to have a user go through a configuration screen, which isn't the nicest user experience.
Inspiring
December 6, 2007
May be if you post more details about your task we can some up with a solution...

Inspiring
December 6, 2007
I am pretty sure that Flash uses the system double click time that the user has set in their OS control panel. I don't know of a way to extract this via Flash.
December 6, 2007
For various reasons, I'm having to implement my own double click detection system. Instead of just hardcoding some double click value (like 300ms), I was hoping to use the exact same value that Flash is using, which is why I was wondering if it is possible to retreive that value from Flash.
Inspiring
December 6, 2007
BSpero is right - Flash cannot read it.

Why use hard-coded value if you can calculate it?

In addition, even if this value were available, still, there is a time lag while event travels through capture phase to target and back to bubble. And this lag depends on the depth of the click originator withing entire stack of Sprites and MovieClips. I guess the answer depends on a precision the app needs to rely on.
Inspiring
December 6, 2007
You can calculate time difference between CLICK and DOUBLE_CLICK events on the same object (in other words - you need two listeners whose timing is recorded and then compared).

DOUBLE_CLICK is essentially two events in a sequence: 1st - CLICK, second - DOUBLE_CLICK.