While the suggestion from Shaun Husain above was close, gestures in AS3 don't provide start and end points so far as I can tell. To get around this, I took a sampling of 5 trigger points from the GESTURE_PAN event and used a variation on Levenshtein Distance calculation to determine the intended direction. Below is the working solution to this problem:
var onPanPointer:Number;
var onPanLevString:String;
var onPanLevSampleSize:Number;
onPanLevSampleSize = 5;
function onPan(e:TransformGestureEvent):void
{
if (Math.abs(e.offsetX) > Math.abs(e.offsetY))
{
// Looks like we intended to move on the X axis
if (e.offsetX > 0)
{
if (onPanLevString == null)
{
onPanLevString = "r"
}
else
{
onPanLevString = onPanLevString + "r"
}
}
else
{
if (onPanLevString == null)
{
onPanLevString = "l"
}
else
{
onPanLevString = onPanLevString + "l"
}
}
}
else
{
// Looks like we intended to move on the Y axis
if (e.offsetY > 0)
{
if (onPanLevString == null)
{
onPanLevString = "d"
}
else
{
onPanLevString = onPanLevString + "d"
}
}
else
{
if (onPanLevString == null)
{
onPanLevString = "u"
}
else
{
onPanLevString = onPanLevString + "u"
}
}
}
if (onPanPointer < onPanLevSampleSize)
{
onPanPointer += 1;
}
else
{
//trace("Pointer Value has reached the desired count of: " + onPanPointer);
//trace("The Levenshtein String is: " + onPanLevString);
if (levenshteinDistance(onPanLevString,repeatString("u",onPanLevSampleSize)) <= ((onPanLevSampleSize/2)+1))
{
e.target.y += e.offsetY*onPanLevSampleSize;
//trace("Panning Up");
}
else if (levenshteinDistance(onPanLevString,repeatString("d",onPanLevSampleSize)) <= ((onPanLevSampleSize/2)+1))
{
e.target.y += e.offsetY*onPanLevSampleSize;
//trace("Panning Down");
}
else if (levenshteinDistance(onPanLevString,repeatString("l",onPanLevSampleSize)) <= ((onPanLevSampleSize/2)+1))
{
e.target.x += e.offsetX*onPanLevSampleSize;
//trace("Panning Left");
}
else
{
e.target.x += e.offsetX*onPanLevSampleSize;
//trace("Panning Right");
}
onPanPointer = 1;
onPanLevString = null;
}
//trace("X Offset = " + e.offsetX);
//trace("Y Offset = " + e.offsetY);
}
The levenshteinDistance function being used (below) was written by mircea16 on Snipplr and can be found here.
function levenshteinDistance(s1:String,s2:String):int
{
var m:int=s1.length;
var n:int=s2.length;
var matrix:Array=new Array();
var line:Array;
var i:int;
var j:int;
for (i=0;i<=m;i++)
{
line=new Array();
for (j=0;j<=n;j++)
{
if (i!=0)line.push(0)
else line.push(j);
}
line[0]=i
matrix.push(line);
}
var cost:int;
for (i=1;i<=m;i++)
for (j=1;j<=n;j++)
{
if (s1.charAt(i-1)==s2.charAt(j-1)) cost=0
else cost=1;
matrix[i][j]=Math.min(matrix[i-1][j]+1,matrix[i][j-1]+1,matrix[i-1][j-1]+cost);
}
return matrix[m][n];
}
And the last function you'll need to make the sample above work is a repeatString function I use. (This is needed to enable you to change the sample size using the onPanLevSampleSize var without having to alter anything else)
function repeatString(string:String, numTimes:uint):String
{
var output:String = "";
for(var i:uint = 0; i < numTimes; i++)
output += string;
return output;
}
The only number you need to change to adjust the sample size used is the onPanLevSampleSize, all the calculations are performed using that number as the basis.
Hope this helps someone in the future!