Determining the direction of a Gesture in Flash CS5 on the iPhone
If you need to find out in what direction a gesture goes, e.g. Up, Down, Left or Right the following Script might help.
-
this.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin)
-
this.addEventListener(TouchEvent.TOUCH_END, onTouchEnd)
-
-
var startPoint:Point;
-
var endPoint:Point;
-
-
function onTouchBegin(e:TouchEvent):void
-
{
-
startPoint = new Point(e.localX, e.localY);
-
}
-
function onTouchEnd(e:TouchEvent):void
-
{
-
endPoint = new Point(e.localX, e.localY);
-
var a:Number = endPoint.y - startPoint.y;
-
var b:Number = endPoint.x - startPoint.x;
-
-
if(a*a> b*b){
-
if(a> 0){
-
//down
-
}else{
-
//up
-
}
-
}else{
-
if(b> 0){
-
//right
-
}else{
-
//left
-
}
-
}
-
}
This entry was posted on Friday, February 5th, 2010 at 12:13 and is filed under Actionscript 3.0, Flash CS5, iphone. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.