CLICK and DOUBLE_CLICK Events

Thursday, May 29th, 2008

I’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

AddThis Feed Button

This is some text prior to the author information. You can change this text from the admin section of WP-Gravatar  I'm living in Bratislava, Slovakia. I'm Senior Flex, AIR Developer for my own company Flexets. Read more from this author


tagged under:

ABOUT THIS AUTHOR

I'm living in Bratislava, Slovakia. I'm Senior Flex, AIR Developer for my own company Flexets.

Get a Trackback link

5 Comments


  1. PaulH
    Visit Site
    May 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.


  2. Eder Fortunato
    Visit Site
    May 30th, 2008

    hi,

    test this code:

    var isDobleClick:Boolean;
    var espera:Timer;

    var bolaAzul:Sprite = new Sprite();
    bolaAzul.graphics.beginFill(0×0000FF);
    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”);
    }

    }


  3. Andrew Traviss
    Visit Site
    June 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.


  4. Heather
    Visit Site
    June 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.


  5. 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;
    };

Live Preview

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

This site is using OpenAvatar based on
Images is enhanced with WordPress Lightbox JS by Zeo