Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 4 of 4

Thread: calculate the mouse movement distance

  1. #1

    calculate the mouse movement distance

    I am wondering if anyone can share with a good example on how to detect the distance of the mouse movement in a certain time. Id like to be able to calculate the distance the mouse was moved from one point to another in certain time (one second) and compare these values. Please let me know if you have any good sample. Thank you in advance.

  2. #2
    As far as I know, there's no built-in API to do this. You might just have to store the mouse X/Y position at a given time, then later compare it to the current mouse position.

    If you want to figure out how much it moved as opposed to its displacement, that would be trickier. That is, in one second, the user could have moved the mouse across the entire screen then back to the starting point. If you compared to start and end points, it would say the user moved very little (or none at all). If that's an issue, then you'll probably have to add up all the distances traveled each frame instead of simply comparing the start and end points.

    Hope that helps!

  3. #3
    You are going to have to use some flash math. More specifically the Pythagorean theory to get the distance. A good tutorial dealing with proximity is http://www.gotoandlearn.com/play?id=17.

  4. #4
    var mX:Number = _xmouse;
    var mY:Number = _ymouse;
    function checkDistance()
    	//trace('new distance: ' + Math.sqrt(Math.pow((mY - _ymouse), 2) + Math.pow((mX - _xmouse), 2)));
    	lineStyle(1, 0x000000);
    	moveTo(mX, mY);
    	lineTo(_xmouse, _ymouse);
    	mX = _xmouse;
    	mY = _ymouse;
    setInterval(checkDistance, 1000);
    sample of post 2...
    Too many letters, I cant understand you.. :vodka::bears:
    If i make grammatical mistakes plz correct me. $)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012