From 51e8435b2dfc2eb9ff4fb6d3e4cedb663feabc67 Mon Sep 17 00:00:00 2001 From: Pavel fljot Date: Thu, 1 Mar 2012 18:12:35 +0200 Subject: [PATCH] Input adapters initialization and disposing --- src/org/gestouch/core/GesturesManager.as | 7 ++++++- src/org/gestouch/core/IGesturesManager.as | 2 +- src/org/gestouch/core/IInputAdapter.as | 3 +++ src/org/gestouch/input/AbstractInputAdapter.as | 14 ++++++++++++++ src/org/gestouch/input/MouseInputAdapter.as | 13 +++++++++++++ src/org/gestouch/input/TouchInputAdapter.as | 13 ++++++++++++- 6 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/org/gestouch/core/GesturesManager.as b/src/org/gestouch/core/GesturesManager.as index 8f872ed..9dc5a02 100644 --- a/src/org/gestouch/core/GesturesManager.as +++ b/src/org/gestouch/core/GesturesManager.as @@ -91,10 +91,11 @@ package org.gestouch.core _inputAdapters.push(inputAdapter); inputAdapter.touchesManager = _touchesManager; inputAdapter.gesturesManager = this; + inputAdapter.init(); } - public function removeInputAdapter(inputAdapter:IInputAdapter):void + public function removeInputAdapter(inputAdapter:IInputAdapter, dispose:Boolean = true):void { if (!inputAdapter) { @@ -107,6 +108,10 @@ package org.gestouch.core } _inputAdapters.splice(index, 1); + if (dispose) + { + inputAdapter.dispose(); + } } diff --git a/src/org/gestouch/core/IGesturesManager.as b/src/org/gestouch/core/IGesturesManager.as index 5c08bfe..297f39a 100644 --- a/src/org/gestouch/core/IGesturesManager.as +++ b/src/org/gestouch/core/IGesturesManager.as @@ -12,6 +12,6 @@ package org.gestouch.core public interface IGesturesManager { function addInputAdapter(inputAdapter:IInputAdapter):void; - function removeInputAdapter(inputAdapter:IInputAdapter):void; + function removeInputAdapter(inputAdapter:IInputAdapter, dispose:Boolean = true):void; } } \ No newline at end of file diff --git a/src/org/gestouch/core/IInputAdapter.as b/src/org/gestouch/core/IInputAdapter.as index 07171f1..337ff0e 100644 --- a/src/org/gestouch/core/IInputAdapter.as +++ b/src/org/gestouch/core/IInputAdapter.as @@ -7,5 +7,8 @@ package org.gestouch.core { function set touchesManager(value:ITouchesManager):void; function set gesturesManager(value:IGesturesManager):void; + + function init():void; + function dispose():void; } } \ No newline at end of file diff --git a/src/org/gestouch/input/AbstractInputAdapter.as b/src/org/gestouch/input/AbstractInputAdapter.as index 5c3bcfc..8543af5 100644 --- a/src/org/gestouch/input/AbstractInputAdapter.as +++ b/src/org/gestouch/input/AbstractInputAdapter.as @@ -33,5 +33,19 @@ package org.gestouch.input { _gesturesManager = value; } + + + [Abstract] + public function init():void + { + throw new Error("This is abstract method."); + } + + + [Abstract] + public function dispose():void + { + throw new Error("This is abstract method."); + } } } \ No newline at end of file diff --git a/src/org/gestouch/input/MouseInputAdapter.as b/src/org/gestouch/input/MouseInputAdapter.as index 0a34d89..51ce265 100644 --- a/src/org/gestouch/input/MouseInputAdapter.as +++ b/src/org/gestouch/input/MouseInputAdapter.as @@ -35,6 +35,19 @@ package org.gestouch.input } + override public function init():void + { + _stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, true); + } + + + override public function dispose():void + { + _stage.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, true); + uninstallStageListeners(); + } + + protected function installStageListeners():void { // Maximum priority to prevent event hijacking diff --git a/src/org/gestouch/input/TouchInputAdapter.as b/src/org/gestouch/input/TouchInputAdapter.as index e1b7263..f4d87a7 100644 --- a/src/org/gestouch/input/TouchInputAdapter.as +++ b/src/org/gestouch/input/TouchInputAdapter.as @@ -35,8 +35,19 @@ package org.gestouch.input } _stage = stage; + } + - stage.addEventListener(TouchEvent.TOUCH_BEGIN, touchBeginHandler, true); + override public function init():void + { + _stage.addEventListener(TouchEvent.TOUCH_BEGIN, touchBeginHandler, true); + } + + + override public function dispose():void + { + _stage.removeEventListener(TouchEvent.TOUCH_BEGIN, touchBeginHandler, true); + uninstallStageListeners(); }