Posted By

heathbo on 10/05/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

davidino1978
alptugan


How to measure the distance between the cursor and a MovieClip


 / Published in: ActionScript 3
 

The problem is, flash only gives you the x,y coordinates of the cursor. So there is no direct way to measure the diagonal distance between the cursor and a MovieClip. In-order to do this, you have to use the Pythagorean Theorem.

  1. //For this example we are calculating from x:0 and y:0;
  2.  
  3. addEventListener(Event.ENTER_FRAME,Calculate);
  4.  
  5. function Calculate()
  6. {
  7. var A = mouse.y;
  8. var B = mouse.x;
  9. var A2 = A * A;
  10. var B2 = B * B;
  11. var Hyp = A2+B2;
  12. var FinalResult = Math.round(Math.sqrt(Hyp));
  13.  
  14. };
  15.  
  16. //FinalResult is the length of the Hypotenuse.

Report this snippet  

You need to login to post a comment.