diff --git a/src/org/gestouch/core/GesturesManager.as b/src/org/gestouch/core/GesturesManager.as index 77b4d96..1820be0 100644 --- a/src/org/gestouch/core/GesturesManager.as +++ b/src/org/gestouch/core/GesturesManager.as @@ -313,7 +313,20 @@ package org.gestouch.core gestouch_internal function onTouchCancel(touch:Touch):void { - //TODO + var gesturesForTouch:Vector. = _gesturesForTouchMap[touch] as Vector.; + var gesture:Gesture; + var i:uint = gesturesForTouch.length; + while (i-- > 0) + { + gesture = gesturesForTouch[i]; + + if (!_dirtyGesturesMap[gesture] && gesture.isTrackingTouch(touch.id)) + { + gesture.touchCancelHandler(touch); + } + } + + gesturesForTouch.length = 0;// release for GC } diff --git a/src/org/gestouch/gestures/Gesture.as b/src/org/gestouch/gestures/Gesture.as index 2772cb8..261f440 100644 --- a/src/org/gestouch/gestures/Gesture.as +++ b/src/org/gestouch/gestures/Gesture.as @@ -407,6 +407,14 @@ package org.gestouch.gestures } + /** + * + */ + protected function onTouchCancel(touch:Touch):void + { + } + + protected function setState(newState:GestureState):Boolean { if (_state == newState && _state == GestureState.CHANGED) @@ -576,6 +584,27 @@ package org.gestouch.gestures } + gestouch_internal function touchCancelHandler(touch:Touch):void + { + delete _touchesMap[touch.id]; + _touchesCount--; + + onTouchCancel(touch); + + if (!state.isEndState) + { + if (state == GestureState.BEGAN || state == GestureState.CHANGED) + { + setState(GestureState.CANCELLED); + } + else + { + setState(GestureState.FAILED); + } + } + } + + protected function gestureToFail_stateChangeHandler(event:GestureStateEvent):void { if (!_pendingRecognizedState || state != GestureState.POSSIBLE)