Actionscript:
-
var velocityInfo:TextField = new TextField();
-
velocityInfo.x = 20;
-
velocityInfo.y = 20;
-
addChild(velocityInfo);
-
-
var prevX:Number = mouseX;
-
var prevY:Number = mouseY;
-
var velX:Number = 0;
-
var velY:Number = 0;
-
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
-
function onLoop(evt:Event):void {
-
-
velX = mouseX - prevX;
-
velY = mouseY - prevY;
-
-
velocityInfo.text = velX + ", " + velY
-
-
prevX = mouseX;
-
prevY = mouseY;
-
}
Wrote this in response to a question from one of my students. The next step is to use velX and velY to push objects around the screen.