From ad767a4937f853d028097a1620ed517a14f34fbe Mon Sep 17 00:00:00 2001 From: Pavel fljot Date: Thu, 2 Feb 2012 16:57:16 +0200 Subject: [PATCH] Bugfix for mouse/finger release out of stage --- src/org/gestouch/core/GesturesManager.as | 7 +++++++ src/org/gestouch/core/TouchesManager.as | 8 ++++++++ src/org/gestouch/events/MouseTouchEvent.as | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/src/org/gestouch/core/GesturesManager.as b/src/org/gestouch/core/GesturesManager.as index d1e8a68..509481d 100644 --- a/src/org/gestouch/core/GesturesManager.as +++ b/src/org/gestouch/core/GesturesManager.as @@ -1,5 +1,6 @@ package org.gestouch.core { + import flash.events.EventPhase; import org.gestouch.events.MouseTouchEvent; import org.gestouch.gestures.Gesture; @@ -198,11 +199,13 @@ package org.gestouch.core { _stage.addEventListener(TouchEvent.TOUCH_MOVE, touchMoveHandler, true); _stage.addEventListener(TouchEvent.TOUCH_END, touchEndHandler, true); + _stage.addEventListener(TouchEvent.TOUCH_END, touchEndHandler);//to catch event out of stage } else { _stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler, true); _stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler, true); + _stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);//to catch event out of stage } } @@ -376,6 +379,10 @@ package org.gestouch.core protected function touchEndHandler(event:TouchEvent):void { + if (event.eventPhase == EventPhase.BUBBLING_PHASE) + return; + + if (_dirtyGesturesLength > 0) { resetDirtyGestures(); diff --git a/src/org/gestouch/core/TouchesManager.as b/src/org/gestouch/core/TouchesManager.as index 6502f8b..a9a4a44 100644 --- a/src/org/gestouch/core/TouchesManager.as +++ b/src/org/gestouch/core/TouchesManager.as @@ -1,5 +1,6 @@ package org.gestouch.core { + import flash.events.EventPhase; import flash.display.InteractiveObject; import flash.display.Stage; import flash.events.MouseEvent; @@ -74,12 +75,16 @@ package org.gestouch.core stage.addEventListener(TouchEvent.TOUCH_BEGIN, stage_touchBeginHandler, true, int.MAX_VALUE); stage.addEventListener(TouchEvent.TOUCH_MOVE, stage_touchMoveHandler, true, int.MAX_VALUE); stage.addEventListener(TouchEvent.TOUCH_END, stage_touchEndHandler, true, int.MAX_VALUE); + // if mouse/finger leaves the stage we will get only AT_TARGET phase + stage.addEventListener(TouchEvent.TOUCH_END, stage_touchEndHandler, false, int.MAX_VALUE); } else { stage.addEventListener(MouseEvent.MOUSE_DOWN, stage_mouseDownHandler, true, int.MAX_VALUE); stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMoveHandler, true, int.MAX_VALUE); stage.addEventListener(MouseEvent.MOUSE_UP, stage_mouseUpHandler, true, int.MAX_VALUE); + // if mouse/finger leaves the stage we will get only AT_TARGET phase + stage.addEventListener(MouseEvent.MOUSE_UP, stage_mouseUpHandler, false, int.MAX_VALUE); } } @@ -187,6 +192,9 @@ package org.gestouch.core protected function stage_mouseUpHandler(event:MouseEvent):void { + if (event.eventPhase == EventPhase.BUBBLING_PHASE) + return; + var touch:Touch = _touchesMap[0] as Touch; if (!touch) { diff --git a/src/org/gestouch/events/MouseTouchEvent.as b/src/org/gestouch/events/MouseTouchEvent.as index e1b7f6c..bff0d64 100644 --- a/src/org/gestouch/events/MouseTouchEvent.as +++ b/src/org/gestouch/events/MouseTouchEvent.as @@ -53,6 +53,12 @@ package org.gestouch.events } + override public function get eventPhase():uint + { + return _mouseEvent.eventPhase; + } + + override public function get stageX():Number { return _mouseEvent.stageX;