Skip to main content
Participant
September 2, 2010
Question

I need help with mouse click between 2 points to figure distance between clicks

  • September 2, 2010
  • 2 replies
  • 718 views

I have an image and I need to be able to click on 2 different points within the image and be able to have it tell me how far apart these 2 points are. Any hints?

This topic has been closed for replies.

2 replies

Inspiring
September 2, 2010

Here is a basic idea:

var prevClick:Point;
stage.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
     var currentClick:Point = new Point(mouseX, mouseY);
     if (!prevClick) prevClick = currentClick;
     else {
          trace("distance = ", Point.distance(prevClick, currentClick));
          prevClick = currentClick;
     }
}

Message was edited by: Andrei1

kglad
Community Expert
Community Expert
September 2, 2010

and what's the problem with that?


Inspiring
September 2, 2010

There is no problem...


kglad
Community Expert
Community Expert
September 2, 2010

how will you determine when you want to record the first and then 2nd click?