views:

268

answers:

2

is it not possible to have both CLICK and DOUBLE_CLICK on the same display object? i'm trying to have both for the stage where double clicking the stage adds a new object and clicking once on the stage deselects a selected object.

it appears that DOUBLE_CLICK will execute both itself as well as the first CLICK functions in the path toward DOUBLE CLICK (mouse down, mouse up, click, mouse down, mouse up, double click).

in other languages i've programmed with there was a built-in timers that set the two apart. is this not available in AS3?


UPDATE

here's some code. essentially what i would like is have one or the other, not both with double click

stage.doubleClickEnabled = true;
stage.addEventListener(MouseEvent.DOUBLE_CLICK, twoClicks, false, 0, true);
stage.addEventListener(MouseEvent.CLICK, oneClick, false, 0, true);

function oneClick(evt:MouseEvent):void
    {
    trace("One CLICK");
    }

function twoClicks(evt:MouseEvent):void
    {
    trace("Two CLICKS");
    }

//oneClick trace = "One CLICK"
//twoClicks trace = "One CLICK Two CLICKS" (instead of just Two CLICKS)
A: 

Did you set .doubleClickEnabled to true?

You should also take a look here.

M28
yes, of course. otherwise double clicking just wouldn't work. i've update my question with code so you can see what i'm trying to do.
TheDarkInI1978
+5  A: 

Well, you could use setTimeout and clearTimeout.

It'd look something like this:

const var DOUBLE_CLICK_SPEED:int = 10;
var mouseTimeout;

function handleClick(evt:MouseEvent):void {
    if (mouseTimeout != undefined) {
        twoClicks();
        clearTimeout(mouseTimeout);
        mouseTimeout = undefined;
    } else {
        function handleSingleClick():void {
            oneClick();
            mouseTimeout = undefined;
        }
        mouseTimeout = setTimeout(handleSingleClick, DOUBLE_CLICK_SPEED);
    }
}

function oneClick(evt:MouseEvent):void {
    trace("One CLICK");
}

function twoClicks(evt:MouseEvent):void {
    trace("Two CLICKS");
}
stage.addEventListener(MouseEvent.CLICK, handleClick, false, 0, true);
Wallacoloo
Yeah, the only problem is that it doesn't consider the user configuration in the system control panel, anyway, it works, voted up :)
M28
Is that even possible to access in Flash?
Wallacoloo