this code will double to detect whether the button has been single clicked or double clicked...
Now the first part is pretty simple, that is making it respond to a double click. All you need to do is find the difference in time between the first click and the second click and if its approximately < 400ms a double click has been made. e.g: create a button myButton then the following code will trace out when you have made a double click
Now the tricky part is to determine whether a user intended a single click rather than a double click. Why? Well because in the process of a double click a single click always occurs. So we kind of need to determine whether a single click or double click was intended by the user.Code:myButton.onRelease = function() { var currTime = getTimer(); var diff = currTime-this.lastTime; if (diff<400) { trace("doubleclicked"); } this.lastTime = currTime; };
So the solution to this is as follows: After a single click has been made a setInterval is started (which after 401 ms will trace out that a single click has occured).
But here's the trick, if the button is pressed again within that time period before the trace has occured, we clear that interval as then we know the user is double clicking the button. Hope that makes sense
Note:Code:myButton.onRelease = function() { currButt = this; clearInterval(this.nTimer); var currTime = getTimer(); var diff = currTime-this.lastTime; this.nTimer = setInterval(timer, 401); if (diff<400) { clearInterval(this.nTimer); trace("doubleclicked"); } function timer() { clearInterval(currButt.nTimer); trace("single clicked"); } this.lastTime = currTime; };
Note there will a half second delay(401 ms to be exact) to determine whether it is a single click as this is the only way of knowing that a double click was not intended..because thats the time (400 ms) we use to determine whether a double click has occured
So in a nutshell:
A user clicks the button.
If he doesnt click it again within 401 ms a single click is registered.
If he clicks it again within <400ms then a double click is registered.




Reply With Quote