CLICK and DOUBLE_CLICK Events
Štvrtok, Máj 29th, 2008I’m curious if anyone need handle both events on same component in same time. Just imagine situation: You got circle. On MouseEvent.CLICK you want to decrease radius by 10px, on MouseEvent.DOUBLE_CLICK increase radius by 10px. It is obvious that when you double click on circle, you dont want to fired both: decrease and increase radius.
Sure, there can be some “workarounds” with timer or “somehow” canceling CLICK event on DOUBLE_CLICK, but I hope there is “normal solution” from Adobe. Can anyone point me to that “normal solution”
P.S. Do not forget to set doubleClickEnabled=”true” to be able to listen to MouseEvent.DOUBLE_CLICK
5 Comments
PaulH
• Visit Site
Máj 30th, 2008
yeah we’ve got a flex app that does some map redlining (markup), it used single mouse clicks to define the redline & double click to end redlining but users used to get a bazillion false hits so we had to swap to using a control-key+click combo to end redlining.
Eder Fortunato
• Visit Site
Máj 30th, 2008
hi,
test this code:
var isDobleClick:Boolean;
var espera:Timer;
var bolaAzul:Sprite = new Sprite();
bolaAzul.graphics.beginFill(0x0000FF);
bolaAzul.graphics.drawCircle(100, 100, 50);
addChild(bolaAzul);
bolaAzul.doubleClickEnabled = true;
bolaAzul.addEventListener(MouseEvent.CLICK, onClick);
bolaAzul.addEventListener(MouseEvent.DOUBLE_CLICK, onDobleClick);
function onClick(event:MouseEvent):void{
isDobleClick = false;
espera = new Timer(200, 1);
espera.addEventListener(TimerEvent.TIMER, controlaClick);
espera.start();
if (event.ctrlKey) {
isDobleClick = true;
}
}
function onDobleClick(event:MouseEvent):void{
isDobleClick = true;
}
function controlaClick(event:TimerEvent):void{
if (isDobleClick == false) {
trace(“click”);
} else {
trace(“doble click”);
}
}
Andrew Traviss
• Visit Site
Jún 6th, 2008
Am I the only one that finds double clicking to be very poor usability, anyway? Especially for those who don’t use computers very frequently. Assigning one function to single click and one to double click, both in the same context, is a recipe for user frustration.
Heather
• Visit Site
Jún 13th, 2008
@Andrew I agree that assigning click vs doubleclick functions to the same object can be confusing, but take a drag and drop scenario where a mouseDown event triggers a drag and a doubleClick event triggers the appearance of a pop-up menu. That’s logical – but the same problems occur.
Jamie Kosoy
• Visit Site
August 2nd, 2008
I’ve abandoned doubleClickEnabled and the MouseEvent.DOUBLE_CLICK. It’s just too inconsistent. The easiest way I’ve found is to simply get a timestamp every time the user clicks (that is, MouseEvent.CLICK or MouseEvent.MOUSE_UP) and if the time between clicks is within a certain range, consider it a double click. I’ve ballparked that about 200 milliseconds between clicks is a double click.
Try adding this to the main timeline of a FLA as a quick test to see what I mean.
var myTimeStamp:Number = new Date().getTime();
stage.addEventListener(MouseEvent.CLICK,doubleClickCheck);
function doubleClickCheck($evt:MouseEvent):void
{
var t:Number = new Date().getTime();
if(t – myTimeStamp < 200) trace(“double click”);
myTimeStamp = t;
};
Sorry, comments for this entry are closed at this time.