
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???
If you would like to make a comment, please fill out the form below.
You have to enable doubleClick first, by default it’s false…
sprite.doubleClickEnabled = true;
sprite.doubleClickEnabled = true; should solve the problem…
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.
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.
you’ve forgotten:
sprite.doubleClickEnabled = true
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);
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.
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?
If you have the property mouseChildren = true;
Double click will not work.
I don’t know if anyone has mentioned this, but you need to set sprite.doubleClickEnabled = true;
hth
Its really simple, all you need to do is set sprite.doubleClickEnabled = false, that should do it!
sprite.doubleClickEnabled = true; is the way to go bro. Just saying.
Hey!
Just do this:
sprite.doubleClickEnabled = true;
sprite.mouseEnabled = true;
sprite.mouseChildren = false; //( if there are any children )
sprite.addEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClickHandler);
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();
}
}
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
Thanks Dale!
Great bit of code. Works far better than the other solutions and is far easier to implement without affecting other code.
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();
//}
}
thanks Dale and bobkatzz!
This code is exactly what I was looking for! Thank you!