No double click at all

By romantique | Jan 17, 2009

actionscript3

Hi guys. I never really dealt with double click in flash, but I’ve been always thinking it’s just the same as any mouse event handling. Here is the simple test code I’ve made:

ActionScript Code:
package {     import flash.display.Sprite;     import flash.events.Event;     import flash.events.MouseEvent;     public class PureAS3Test extends Sprite     {         public function PureAS3Test()         {             if( stage )                 init();             else                 addEventListener(Event.ADDED_TO_STAGE,init);         }                 private function init(event:Event=null):void         {             removeEventListener(Event.ADDED_TO_STAGE,init);                         var sprite:Sprite = new Sprite();             sprite.x = 0;             sprite.y = 0;             sprite.graphics.beginFill(0xff0000);             sprite.graphics.drawCircle(0,0,100);             sprite.graphics.endFill();                         addChild(sprite);                         sprite.addEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClick);         }                 private function onDoubleClick(event:MouseEvent):void         {             trace(“double click”);         }     } }

I’m really sick of clicking that red circle, but I got no event firing at all. I’ve changed windows double-click settings, have made another testing mouse listeners (all of them are firing) and all the things… None of them made effect.

What am I doing wrong???

actionscript3

Please reply at our Forum

18 Comments so far
  1. T Hannelin January 19, 2009 7:00 pm

    You have to enable doubleClick first, by default it’s false…

    sprite.doubleClickEnabled = true;

  2. Martijn January 28, 2009 10:15 am

    sprite.doubleClickEnabled = true; should solve the problem…

  3. Anil February 4, 2009 10:22 pm

    In order for the DOUBLE_CLICK event to be captured, the MovieClip, or Sprite in this case, you must first have the doubleClickEnabled property set to true.

    Give that a try and see if that solves your problem.

  4. Anil February 4, 2009 10:23 pm

    Looks like I entered the wrong email address in my previous message to solve your problem. This post has my correct email address in case you want to contact me directly with any questions. :)

  5. Ilya Rumeyev February 5, 2009 2:42 pm

    you’ve forgotten:

    sprite.doubleClickEnabled = true

  6. kloff February 5, 2009 4:01 pm

    Hi man,
    you have to set some things before you can listen to doubleclick event in as3.
    Try this:
    sprite.doubleClickEnabled = true;
    sprite.mouseEnabled = true;
    sprite.addEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClickHandler);

  7. someotherdude March 18, 2009 5:01 pm

    well, it looks like you’ve forgotten to enable the double click event for the sprite. if you enable that i’m sure it will work.

    give this a try:
    sprite.doubleClickEnabled = true;

    hope this was helpful mate.

  8. Hey guys June 3, 2009 8:53 pm

    What’s with all the duplicate solutions? Do you guys read the previous posts at all? Or do you like thinking that you are clever?

  9. Gerardo June 18, 2009 8:27 pm

    If you have the property mouseChildren = true;

    Double click will not work.

  10. wtfbbq June 22, 2009 10:04 am

    I don’t know if anyone has mentioned this, but you need to set sprite.doubleClickEnabled = true;

    hth

  11. Steven August 24, 2009 3:09 pm

    Its really simple, all you need to do is set sprite.doubleClickEnabled = false, that should do it!

  12. retardedKevin September 4, 2009 6:24 pm

    sprite.doubleClickEnabled = true; is the way to go bro. Just saying.

  13. Max Nylin November 2, 2009 9:25 am

    Hey!

    Just do this:
    sprite.doubleClickEnabled = true;
    sprite.mouseEnabled = true;
    sprite.mouseChildren = false; //( if there are any children )
    sprite.addEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClickHandler);

  14. Dale J Williams November 5, 2009 12:05 am

    Double click events are nasty and too restrictive for mouse-heavy applications. They prevent alot of mouse interaction. I would suggest that you use a custom bit of code like this for anything more advanced. Bro.

    const CLICK_TIME:int = 300;
    var doubleTimer:int;
    addEventListener(MouseEvent.CLICK, handleMouseClick);
    function handleMouseClick(e:MouseEvent):void {
    if (e.type == MouseEvent.CLICK) {
    if (getTimer() - doubleTimer < CLICK_TIME)
    // execute code or dispatch event here
    doubleTimer = getTimer();
    }
    }

  15. Jörgen Bang November 13, 2009 4:09 pm

    Dale’s solution, using getTimer() instead helped me a lot, as i’m working on an application with lots of nested layers with objects that are lying on top of each. Setting mouseChildren etc on everything that’s affected would be a nightmare :)

  16. Jason Ramirez January 13, 2010 8:24 pm

    Thanks Dale!

    Great bit of code. Works far better than the other solutions and is far easier to implement without affecting other code.

  17. bobkatzz January 20, 2010 8:58 pm

    that code is wrong -

    doubleTimer = getTimer();
    needs to be outside the loop that it’s shown in. I don’t know how it worked for you. This worked for me::

    import flash.utils.getTimer;

    const CLICK_TIME:int = 600;
    var doubleTimer:int;

    myButt.addEventListener(MouseEvent.CLICK, handleMouseClick);

    function handleMouseClick(e:MouseEvent):void {
    trace(”the time is - ” + getTimer() + ” and the diff is ” + (getTimer() - doubleTimer) );
    //if (e.type == MouseEvent.CLICK) {
    if (getTimer() - doubleTimer < CLICK_TIME) {
    trace(”Dude you totally double clicked!!”);
    }
    doubleTimer = getTimer();
    //}
    }

  18. oxid March 22, 2010 4:05 pm

    thanks Dale and bobkatzz!
    This code is exactly what I was looking for! Thank you!

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0