Map a Number within one range to another range - From http://snipplr.com/view/65580/
public static function map(num:Number, min1:Number, max1:Number, min2:Number, max2:Number, round:Boolean = false, constrainMin:Boolean = true, constrainMax:Boolean = true):Number
{
if (constrainMin && num < min1) return min2;
if (constrainMax && num > max1) return max2;
var num1:Number = (num - min1) / (max1 - min1);
var num2:Number = (num1 * (max2 - min2)) + min2;
if (round) return Math.round(num2);
return num2;
}