Try using onMouseMove/onEnterFrame to collect the mouse position. You are
sure to get changes per frame with either approach, but onMouseMove is
probably better in terms of performance.

Still use setInterval to get the data collected last from onMouseMove and
average the data to get a measurement at some rate, for example, 3 pixels
per 100 milliseconds if setInterval were set to 100.

Not sure if that's what you're looking for, hope it's of help.

On 6/20/07, eric e. dolecki <[EMAIL PROTECTED]> wrote:

I am calculating mouse velocity, but every now and then you get a 0 for
velocity eventhough its not 0 (setInterval prob I suspect).  Any better
approach?

var MouseX;
var MouseY;

function determineVelocity():Void
{
    MouseX = _root._xmouse
    MouseY = _root._ymouse
    setTimeout( calc, 9 );
};

setInterval( determineVelocity, 20 );

function calc():Void
{
    var newMouseX:Number = _root._xmouse;
    var newMouseY:Number = _root._ymouse;

    var deltaX = Math.abs(MouseX - newMouseX)
    deltaY = Math.abs(MouseY - newMouseY)
    dist = Math.sqrt((deltaX * deltaX) + (deltaY * deltaY))
    velocity = dist*31; // 31 = fps
    trace( velocity );
};
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to