Input adapters initialization and disposing

This commit is contained in:
Pavel fljot 2012-03-01 18:12:35 +02:00
parent 895e662bd5
commit 51e8435b2d
6 changed files with 49 additions and 3 deletions

View file

@ -91,10 +91,11 @@ package org.gestouch.core
_inputAdapters.push(inputAdapter); _inputAdapters.push(inputAdapter);
inputAdapter.touchesManager = _touchesManager; inputAdapter.touchesManager = _touchesManager;
inputAdapter.gesturesManager = this; inputAdapter.gesturesManager = this;
inputAdapter.init();
} }
public function removeInputAdapter(inputAdapter:IInputAdapter):void public function removeInputAdapter(inputAdapter:IInputAdapter, dispose:Boolean = true):void
{ {
if (!inputAdapter) if (!inputAdapter)
{ {
@ -107,6 +108,10 @@ package org.gestouch.core
} }
_inputAdapters.splice(index, 1); _inputAdapters.splice(index, 1);
if (dispose)
{
inputAdapter.dispose();
}
} }

View file

@ -12,6 +12,6 @@ package org.gestouch.core
public interface IGesturesManager public interface IGesturesManager
{ {
function addInputAdapter(inputAdapter:IInputAdapter):void; function addInputAdapter(inputAdapter:IInputAdapter):void;
function removeInputAdapter(inputAdapter:IInputAdapter):void; function removeInputAdapter(inputAdapter:IInputAdapter, dispose:Boolean = true):void;
} }
} }

View file

@ -7,5 +7,8 @@ package org.gestouch.core
{ {
function set touchesManager(value:ITouchesManager):void; function set touchesManager(value:ITouchesManager):void;
function set gesturesManager(value:IGesturesManager):void; function set gesturesManager(value:IGesturesManager):void;
function init():void;
function dispose():void;
} }
} }

View file

@ -33,5 +33,19 @@ package org.gestouch.input
{ {
_gesturesManager = value; _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.");
}
} }
} }

View file

@ -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 protected function installStageListeners():void
{ {
// Maximum priority to prevent event hijacking // Maximum priority to prevent event hijacking

View file

@ -35,8 +35,19 @@ package org.gestouch.input
} }
_stage = stage; _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();
} }