Drag

  
  

Using the Drag Gesture

Drag returns the horizontal and vertical magnitude of change between the user touching and removing their touch from a multitouch surface.

Mechanics and Code Samples

To register a ‘drag’ event, finger(s) must touch down on the screen, slide to another location and then be lifted up again.

Enable the Drag gesture on a TouchSprite ("myTouchSprite" in this example) by adding the gesture to the gestureList property for the TouchSprite:

1
myTouchSprite.gestureList = {"n-drag":true};

Register an event for the gesture by listening for the 'DRAG' GWGestureEvent:

2
myTouchSprite.addEventListener(GWGestureEvent.DRAG, gestureDragHandler);

Finally, implement the script(s) that you want to respond to the event in a custom handler:

3
4
5
6
7
8
private function gestureDragHandler(event:GWGestureEvent):void
{
    trace("g drag: ", event.value.dx, event.value.dy);
    event.target.$x += event.value.dx;
    event.target.$y += event.value.dy;
}

In this example, the x and y coordinate delta values of the Drag gesture are being sent used to perform a translation using the custom built in affine transform methods.

Gestures can be utilized with a number of touch points. For detailed information about this gesture and more, consult the GestureML Wiki.