Added GestureTrackingEvent (GESTURE_TRACKING_BEGIN, GESTURE_TRACKING_END),

made Gesture extend EventDispatcher (and IGesture extend IEventDispatcher)
This commit is contained in:
Pavel fljot 2011-05-05 19:14:49 +03:00
parent ad8b5a2ecd
commit b765eba46a
4 changed files with 58 additions and 5 deletions

View file

@ -85,7 +85,7 @@ package org.gestouch.core
_stage.addEventListener(MouseEvent.MOUSE_DOWN, stage_mouseDownHandler);
_stage.addEventListener(TouchEvent.TOUCH_BEGIN, stage_touchBeginHandler);
_stage.addEventListener(TouchEvent.TOUCH_MOVE, stage_touchMoveHandler);
_stage.addEventListener(TouchEvent.TOUCH_END, stage_touchEndHandler);
_stage.addEventListener(TouchEvent.TOUCH_END, stage_touchEndHandler, true);
}

View file

@ -1,12 +1,13 @@
package org.gestouch.core
{
import flash.events.IEventDispatcher;
import flash.display.InteractiveObject;
import flash.events.TouchEvent;
/**
* @author Pavel fljot
*/
public interface IGesture
public interface IGesture extends IEventDispatcher
{
function get target():InteractiveObject;
function get trackingPoints():Vector.<TouchPoint>;

View file

@ -0,0 +1,32 @@
package org.gestouch.events
{
import flash.events.Event;
/**
* @author Pavel fljot
*/
public class GestureTrackingEvent extends Event
{
public static const GESTURE_TRACKING_BEGIN:String = "gestureTrackingBegin";
public static const GESTURE_TRACKING_END:String = "gestureTrackingEnd";
public function GestureTrackingEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false)
{
super(type, bubbles, cancelable);
}
override public function clone():Event
{
return new GestureTrackingEvent(type, bubbles, cancelable);
}
override public function toString():String
{
return formatToString("GestureTrackingEvent", "type", "bubbles", "cancelable", "eventPhase");
}
}
}

View file

@ -1,5 +1,7 @@
package org.gestouch.gestures
{
import org.gestouch.events.GestureTrackingEvent;
import flash.events.EventDispatcher;
import flash.errors.IllegalOperationError;
import flash.display.InteractiveObject;
import flash.events.GestureEvent;
@ -13,13 +15,15 @@ package org.gestouch.gestures
import org.gestouch.core.gestouch_internal;
[Event(name="gestureTrackingBegin", type="org.gestouch.events.GestureTrackingEvent")]
[Event(name="gestureTrackingEnd", type="org.gestouch.events.GestureTrackingEvent")]
/**
* Base class for all gestures. Gesture is essentially a detector that tracks touch points
* in order detect specific gesture motion and form gesture event on target.
*
* @author Pavel fljot
*/
public class Gesture implements IGesture
public class Gesture extends EventDispatcher implements IGesture
{
/**
* Threshold for screen distance they must move to count as valid input
@ -448,6 +452,14 @@ _propertyNames.push("timeThreshold", "moveThreshold");
{
_adjustCentralPoint();
}
if (_trackingPointsCount == minTouchPointsCount)
{
if (hasEventListener(GestureTrackingEvent.GESTURE_TRACKING_BEGIN))
{
dispatchEvent(new GestureTrackingEvent(GestureTrackingEvent.GESTURE_TRACKING_BEGIN));
}
}
}
@ -467,6 +479,14 @@ _propertyNames.push("timeThreshold", "moveThreshold");
_trackingPointsCount--;
_adjustCentralPoint();
if (_trackingPointsCount == minTouchPointsCount + 1)
{
if (hasEventListener(GestureTrackingEvent.GESTURE_TRACKING_END))
{
dispatchEvent(new GestureTrackingEvent(GestureTrackingEvent.GESTURE_TRACKING_END));
}
}
}