From 2678e12de8fb3273b57b9f38c5b73e25076c6db2 Mon Sep 17 00:00:00 2001 From: Pavel fljot Date: Tue, 7 Aug 2012 17:46:12 +0300 Subject: [PATCH] Add protected from a mistyped event listening --- src/org/gestouch/gestures/Gesture.as | 20 ++++++++++++++++++- src/org/gestouch/gestures/LongPressGesture.as | 8 +++++++- src/org/gestouch/gestures/PanGesture.as | 6 ++++++ src/org/gestouch/gestures/RotateGesture.as | 6 ++++++ src/org/gestouch/gestures/SwipeGesture.as | 6 ++++++ src/org/gestouch/gestures/TapGesture.as | 6 ++++++ src/org/gestouch/gestures/TransformGesture.as | 6 ++++++ src/org/gestouch/gestures/ZoomGesture.as | 6 ++++++ 8 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/org/gestouch/gestures/Gesture.as b/src/org/gestouch/gestures/Gesture.as index 261f440..5da26ca 100644 --- a/src/org/gestouch/gestures/Gesture.as +++ b/src/org/gestouch/gestures/Gesture.as @@ -198,7 +198,18 @@ package org.gestouch.gestures // // Public methods // - //-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + + override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void + { + if (!eventTypeIsValid(type)) + { + throw new ArgumentError("Event type does not match any of allowed values."); + } + + super.addEventListener(type, listener, useCapture, priority, useWeakReference); + } + [Abstract] /** @@ -546,6 +557,13 @@ package org.gestouch.gestures } + protected function eventTypeIsValid(type:String):Boolean + { + // propertyChange just in case for bindings? + return type == GestureStateEvent.STATE_CHANGE || type == "propertyChange"; + } + + //-------------------------------------------------------------------------- diff --git a/src/org/gestouch/gestures/LongPressGesture.as b/src/org/gestouch/gestures/LongPressGesture.as index 065713e..7ef5632 100644 --- a/src/org/gestouch/gestures/LongPressGesture.as +++ b/src/org/gestouch/gestures/LongPressGesture.as @@ -53,7 +53,7 @@ package org.gestouch.gestures return TapGesture; } - + override public function reset():void { super.reset(); @@ -71,6 +71,12 @@ package org.gestouch.gestures // // -------------------------------------------------------------------------- + override protected function eventTypeIsValid(type:String):Boolean + { + return type == LongPressGestureEvent.GESTURE_LONG_PRESS || super.eventTypeIsValid(type); + } + + override protected function preinit():void { super.preinit(); diff --git a/src/org/gestouch/gestures/PanGesture.as b/src/org/gestouch/gestures/PanGesture.as index 812044a..6dbf6e2 100644 --- a/src/org/gestouch/gestures/PanGesture.as +++ b/src/org/gestouch/gestures/PanGesture.as @@ -112,6 +112,12 @@ package org.gestouch.gestures // // -------------------------------------------------------------------------- + override protected function eventTypeIsValid(type:String):Boolean + { + return type == PanGestureEvent.GESTURE_PAN || super.eventTypeIsValid(type); + } + + override protected function onTouchBegin(touch:Touch):void { if (touchesCount > maxNumTouchesRequired) diff --git a/src/org/gestouch/gestures/RotateGesture.as b/src/org/gestouch/gestures/RotateGesture.as index 73f09fc..1766c6a 100644 --- a/src/org/gestouch/gestures/RotateGesture.as +++ b/src/org/gestouch/gestures/RotateGesture.as @@ -56,6 +56,12 @@ package org.gestouch.gestures // // -------------------------------------------------------------------------- + override protected function eventTypeIsValid(type:String):Boolean + { + return type == RotateGestureEvent.GESTURE_ROTATE || super.eventTypeIsValid(type); + } + + override protected function onTouchBegin(touch:Touch):void { if (touchesCount > 2) diff --git a/src/org/gestouch/gestures/SwipeGesture.as b/src/org/gestouch/gestures/SwipeGesture.as index 6063956..e464206 100644 --- a/src/org/gestouch/gestures/SwipeGesture.as +++ b/src/org/gestouch/gestures/SwipeGesture.as @@ -120,6 +120,12 @@ package org.gestouch.gestures // // -------------------------------------------------------------------------- + override protected function eventTypeIsValid(type:String):Boolean + { + return type == SwipeGestureEvent.GESTURE_SWIPE || super.eventTypeIsValid(type); + } + + override protected function preinit():void { super.preinit(); diff --git a/src/org/gestouch/gestures/TapGesture.as b/src/org/gestouch/gestures/TapGesture.as index 971e8a2..5d5b6a3 100644 --- a/src/org/gestouch/gestures/TapGesture.as +++ b/src/org/gestouch/gestures/TapGesture.as @@ -79,6 +79,12 @@ package org.gestouch.gestures // // -------------------------------------------------------------------------- + override protected function eventTypeIsValid(type:String):Boolean + { + return type == TapGestureEvent.GESTURE_TAP || super.eventTypeIsValid(type); + } + + override protected function preinit():void { super.preinit(); diff --git a/src/org/gestouch/gestures/TransformGesture.as b/src/org/gestouch/gestures/TransformGesture.as index aff0cf9..909eb14 100644 --- a/src/org/gestouch/gestures/TransformGesture.as +++ b/src/org/gestouch/gestures/TransformGesture.as @@ -61,6 +61,12 @@ package org.gestouch.gestures // // -------------------------------------------------------------------------- + override protected function eventTypeIsValid(type:String):Boolean + { + return type == TransformGestureEvent.GESTURE_TRANSFORM || super.eventTypeIsValid(type); + } + + override protected function onTouchBegin(touch:Touch):void { if (touchesCount > 2) diff --git a/src/org/gestouch/gestures/ZoomGesture.as b/src/org/gestouch/gestures/ZoomGesture.as index 4cc8239..49f7197 100644 --- a/src/org/gestouch/gestures/ZoomGesture.as +++ b/src/org/gestouch/gestures/ZoomGesture.as @@ -55,6 +55,12 @@ package org.gestouch.gestures // // -------------------------------------------------------------------------- + override protected function eventTypeIsValid(type:String):Boolean + { + return type == ZoomGestureEvent.GESTURE_ZOOM || super.eventTypeIsValid(type); + } + + override protected function onTouchBegin(touch:Touch):void { if (touchesCount > 2)