PDA

View Full Version : Differentiate between MOUSE_CLICK and MOUSE DOWN/UP (help?)


empy
02-04-2008, 03:30 AM
I have some objects that I want to be able to click and drag (I'm using MOUSE_DOWN, and MOUSE_UP for that), but I also want to be able to single click the nodes to open a URL (with MOUSE_CLICK).
I do not want to have to use DOUBLE_CLICK.

Is there any way to make this work so that when I MOUSE_DOWN/MOUSE_UP it doesn't count as a click? Is there something better to use?

Thank You

Clox
02-04-2008, 03:54 AM
You could do something like this...


import flash.utils.getTimer;

var lastClick:int;
box.addEventListener("mouseDown", mdh);
function mdh (event) {
box.startDrag();
lastClick=getTimer();
}
box.addEventListener("mouseUp", muh);
function muh (event) {
box.stopDrag();
if (lastClick+250>getTimer()) {
trace ("click");
}
}

When the mouse is released, it checks if it has passed more than 250 milliseconds since it was pressed down. And if it hasn't, it counts as a click.

empy
02-04-2008, 04:17 AM
Cheers!
Great idea.

Hambo
02-04-2008, 07:46 AM
had the same problem. using onclick sorted it.

this.addEventListener(MouseEvent.CLICK , Open);