2008/08/29

Why it's not work when use MouseEvent.DOUBLE_CLICK in AS3?

recently, I use the MouseEvent.DOUBLE_CLICK event. it is very short simple codes.

/*=========================*/
import flash.display.Sprite;
import flash.events.MouseEvent;
/*=========================*/
someInstance.addEventListener(MouseEvent.DOUBLE_CLICK, onSomeFunction);
private function onSomeFunction(event:MouseEvent):void{
trace('double click');
}
/*=========================*/

And the code doesn't work.....finally, i search on net. find someone post the reason. it is cause double click will trigger button mode focus--up over down hitTest twice, so if your someInstance have children like MovieClip or some can focus instances inside. It will cause the focus change when you click it second time. so this event doesn't work. the solution is following:

/*=========================*/
import flash.display.Sprite;
import flash.events.MouseEvent;
/*=========================*/
someInstance.mouseChildren=false;
someInstance.addEventListener(MouseEvent.DOUBLE_CLICK, onSomeFunction);
private function onSomeFunction(event:MouseEvent):void{
trace('double click');
}
/*=========================*/

then it works successfully.

沒有留言: