Created
July 29, 2011 20:26
-
-
Save johnlindquist/1114661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<s:Image xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> | |
<s:initialize><![CDATA[ | |
addEventListener(DragGestureEvent.GESTURE_DRAG, gestureDragHandler); | |
dragGesture = DragGesture.add(this, {maxTouchPointsCount: 1}); | |
addEventListener(ZoomGestureEvent.GESTURE_ZOOM, gestureZoomHandler); | |
zoomGesture = ZoomGesture.add(this); | |
]]></s:initialize> | |
<fx:Script><![CDATA[ | |
import org.gestouch.events.DragGestureEvent; | |
import org.gestouch.events.ZoomGestureEvent; | |
import org.gestouch.gestures.DragGesture; | |
import org.gestouch.gestures.ZoomGesture; | |
private var dragGesture:DragGesture; | |
private var zoomGesture:ZoomGesture; | |
public static const MAX_SCALE:Number = 3; | |
public static const MIN_SCALE:Number = .9; | |
private function gestureDragHandler(event:DragGestureEvent):void { | |
if(event.phase == GesturePhase.BEGIN) { | |
} | |
if(event.phase == GesturePhase.UPDATE) { | |
x += event.offsetX; | |
y += event.offsetY; | |
} | |
if(event.phase == GesturePhase.END) { | |
} | |
} | |
private function gestureZoomHandler(event:ZoomGestureEvent):void { | |
if(event.phase == GesturePhase.BEGIN) { | |
dragGesture.cancel(); | |
} | |
if(event.phase == GesturePhase.UPDATE) { | |
transformX = event.localX; | |
transformY = event.localY; | |
scaleX *= event.scaleX; | |
scaleY *= event.scaleY; | |
if(scaleX > MAX_SCALE) { | |
scaleX = scaleY = MAX_SCALE; | |
} | |
if(scaleX < MIN_SCALE) { | |
scaleX = scaleY = MIN_SCALE; | |
} | |
} | |
if(event.phase == GesturePhase.END) { | |
dragGesture.pickAndContinue(zoomGesture); | |
} | |
} | |
]]></fx:Script> | |
</s:Image> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment