mirror of
https://github.com/scratchfoundation/Gestouch.git
synced 2024-11-23 07:47:59 -05:00
Input adapters fix to catch events on empty stage
This commit is contained in:
parent
97486ba2fe
commit
e14bbd11bb
3 changed files with 25 additions and 16 deletions
|
@ -1,7 +1,5 @@
|
|||
package org.gestouch.core
|
||||
{
|
||||
import flash.ui.Multitouch;
|
||||
import flash.ui.MultitouchInputMode;
|
||||
/**
|
||||
* @author Pavel fljot
|
||||
*/
|
||||
|
@ -12,10 +10,6 @@ package org.gestouch.core
|
|||
|
||||
protected var _touchesMap:Object = {};
|
||||
|
||||
{
|
||||
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
|
||||
}
|
||||
|
||||
|
||||
public function TouchesManager()
|
||||
{
|
||||
|
|
|
@ -31,20 +31,20 @@ package org.gestouch.input
|
|||
}
|
||||
|
||||
_stage = stage;
|
||||
|
||||
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, true);
|
||||
}
|
||||
|
||||
|
||||
override public function init():void
|
||||
{
|
||||
_stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, true);
|
||||
_stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);// to catch with EventPhase.AT_TARGET
|
||||
}
|
||||
|
||||
|
||||
override public function dispose():void
|
||||
{
|
||||
_stage.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, true);
|
||||
_stage.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
|
||||
uninstallStageListeners();
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,8 @@ package org.gestouch.input
|
|||
{
|
||||
// Maximum priority to prevent event hijacking
|
||||
_stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler, true, int.MAX_VALUE);
|
||||
_stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler, false, int.MAX_VALUE);
|
||||
_stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler, true, int.MAX_VALUE);
|
||||
// To catch event out of stage
|
||||
_stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler, false, int.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,7 @@ package org.gestouch.input
|
|||
protected function uninstallStageListeners():void
|
||||
{
|
||||
_stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler, true);
|
||||
_stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
|
||||
_stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler, true);
|
||||
_stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
|
||||
}
|
||||
|
@ -69,6 +70,8 @@ package org.gestouch.input
|
|||
|
||||
protected function mouseDownHandler(event:MouseEvent):void
|
||||
{
|
||||
if (event.eventPhase == EventPhase.BUBBLING_PHASE)
|
||||
return;//we listen in capture or at_target (to catch on empty stage)
|
||||
// Way to prevent MouseEvent/TouchEvent collisions.
|
||||
// Also helps to ignore possible fake events.
|
||||
if (_touchesManager.hasTouch(PRIMARY_TOUCH_POINT_ID))
|
||||
|
@ -77,8 +80,8 @@ package org.gestouch.input
|
|||
installStageListeners();
|
||||
|
||||
var touch:Touch = _touchesManager.createTouch();
|
||||
touch.id = 0;
|
||||
touch.target = event.target as InteractiveObject;
|
||||
touch.id = PRIMARY_TOUCH_POINT_ID;
|
||||
touch.gestouch_internal::setLocation(new Point(event.stageX, event.stageY));
|
||||
touch.gestouch_internal::setTime(getTimer());
|
||||
touch.gestouch_internal::setBeginTime(getTimer());
|
||||
|
@ -91,6 +94,8 @@ package org.gestouch.input
|
|||
|
||||
protected function mouseMoveHandler(event:MouseEvent):void
|
||||
{
|
||||
if (event.eventPhase == EventPhase.BUBBLING_PHASE)
|
||||
return;//we listen in capture or at_target (to catch on empty stage)
|
||||
// Way to prevent MouseEvent/TouchEvent collisions.
|
||||
// Also helps to ignore possible fake events.
|
||||
if (!_touchesManager.hasTouch(PRIMARY_TOUCH_POINT_ID))
|
||||
|
@ -106,10 +111,8 @@ package org.gestouch.input
|
|||
|
||||
protected function mouseUpHandler(event:MouseEvent):void
|
||||
{
|
||||
// If event happens outside of stage it will be with AT_TARGET phase
|
||||
if (event.eventPhase == EventPhase.BUBBLING_PHASE)
|
||||
return;
|
||||
|
||||
return;//we listen in capture or at_target (to catch on empty stage)
|
||||
|
||||
// Way to prevent MouseEvent/TouchEvent collisions.
|
||||
// Also helps to ignore possible fake events.
|
||||
|
|
|
@ -8,6 +8,8 @@ package org.gestouch.input
|
|||
import flash.events.EventPhase;
|
||||
import flash.events.TouchEvent;
|
||||
import flash.geom.Point;
|
||||
import flash.ui.Multitouch;
|
||||
import flash.ui.MultitouchInputMode;
|
||||
import flash.utils.getTimer;
|
||||
|
||||
|
||||
|
@ -25,6 +27,10 @@ package org.gestouch.input
|
|||
*/
|
||||
protected var _touchesMap:Object = {};
|
||||
|
||||
{
|
||||
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
|
||||
}
|
||||
|
||||
|
||||
public function TouchInputAdapter(stage:Stage)
|
||||
{
|
||||
|
@ -42,12 +48,14 @@ package org.gestouch.input
|
|||
override public function init():void
|
||||
{
|
||||
_stage.addEventListener(TouchEvent.TOUCH_BEGIN, touchBeginHandler, true);
|
||||
_stage.addEventListener(TouchEvent.TOUCH_BEGIN, touchBeginHandler);// to catch with EventPhase.AT_TARGET
|
||||
}
|
||||
|
||||
|
||||
override public function dispose():void
|
||||
{
|
||||
_stage.removeEventListener(TouchEvent.TOUCH_BEGIN, touchBeginHandler, true);
|
||||
_stage.removeEventListener(TouchEvent.TOUCH_BEGIN, touchBeginHandler);
|
||||
uninstallStageListeners();
|
||||
}
|
||||
|
||||
|
@ -56,8 +64,8 @@ package org.gestouch.input
|
|||
{
|
||||
// Maximum priority to prevent event hijacking
|
||||
_stage.addEventListener(TouchEvent.TOUCH_MOVE, touchMoveHandler, true, int.MAX_VALUE);
|
||||
_stage.addEventListener(TouchEvent.TOUCH_MOVE, touchMoveHandler, false, int.MAX_VALUE);
|
||||
_stage.addEventListener(TouchEvent.TOUCH_END, touchEndHandler, true, int.MAX_VALUE);
|
||||
// To catch event out of stage
|
||||
_stage.addEventListener(TouchEvent.TOUCH_END, touchEndHandler, false, int.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
@ -65,6 +73,7 @@ package org.gestouch.input
|
|||
protected function uninstallStageListeners():void
|
||||
{
|
||||
_stage.removeEventListener(TouchEvent.TOUCH_MOVE, touchMoveHandler, true);
|
||||
_stage.removeEventListener(TouchEvent.TOUCH_MOVE, touchMoveHandler);
|
||||
_stage.removeEventListener(TouchEvent.TOUCH_END, touchEndHandler, true);
|
||||
_stage.removeEventListener(TouchEvent.TOUCH_END, touchEndHandler);
|
||||
}
|
||||
|
@ -72,6 +81,8 @@ package org.gestouch.input
|
|||
|
||||
protected function touchBeginHandler(event:TouchEvent):void
|
||||
{
|
||||
if (event.eventPhase == EventPhase.BUBBLING_PHASE)
|
||||
return;//we listen in capture or at_target (to catch on empty stage)
|
||||
// Way to prevent MouseEvent/TouchEvent collisions.
|
||||
// Also helps to ignore possible fake events.
|
||||
if (_touchesManager.hasTouch(event.touchPointID))
|
||||
|
@ -107,6 +118,8 @@ package org.gestouch.input
|
|||
|
||||
protected function touchMoveHandler(event:TouchEvent):void
|
||||
{
|
||||
if (event.eventPhase == EventPhase.BUBBLING_PHASE)
|
||||
return;//we listen in capture or at_target (to catch on empty stage)
|
||||
// Way to prevent MouseEvent/TouchEvent collisions.
|
||||
// Also helps to ignore possible fake events.
|
||||
if (!_touchesManager.hasTouch(event.touchPointID) || !_touchesMap.hasOwnProperty(event.touchPointID))
|
||||
|
@ -133,9 +146,8 @@ package org.gestouch.input
|
|||
|
||||
protected function touchEndHandler(event:TouchEvent):void
|
||||
{
|
||||
// If event happens outside of stage it will be with AT_TARGET phase
|
||||
if (event.eventPhase == EventPhase.BUBBLING_PHASE)
|
||||
return;
|
||||
return;//we listen in capture or at_target (to catch on empty stage)
|
||||
|
||||
// Way to prevent MouseEvent/TouchEvent collisions.
|
||||
// Also helps to ignore possible fake events.
|
||||
|
|
Loading…
Reference in a new issue