Copy link to clipboard
Copied
Hi,
I need to be able to draw lines dynamically between several sets of 2 dragged/dropped points on stage.
If I draw a line dynamically between a set of 2 points (LineA), using graphics class, moveTo(point1.x, point1.y), lineTo (point2.x, Point2.y), and I want to then get LineA's length (length of the newly drawn line), plus LineA.x, LineA.y, would I simply use LineA.width, LineA.x, LineA.y?
I'm not sure how else to do this?
Any suggestions appreciated.
saratogacoach
if you want the distance between the centers, use the function in my last message and leave the dots' reg points in their centers.
Copy link to clipboard
Copied
use distanceF():
function distanceF(pt1:Point,pt2:Point):Number{
return Math.sqrt((pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y));
}
Copy link to clipboard
Copied
I think I didn't explain fully. While I used the term "points" what I meant was "dots." The user drags and drops two 6X6 dots on the stage, then dynamically draws a line between these 2 dots.
So a set of 2 dots (the beginning and end for the dynamically drawn line between them). Then need to get the length of the drawn line, maybe also its x, y.
Would I still use distanceF() ? Or some other way?
Copy link to clipboard
Copied
use:
function distanceF(pt1:DisplayObject,pt2:DisplayObject):Number{
return Math.sqrt((pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y));
}
Copy link to clipboard
Copied
One clarification:
The dots being dragged/dropped are movieclips that I am creating with a center registration point. Should I instead create these with top left registration. My goal is to get an accurate measure of the distance between the centers of the 2 dots (line length drawn from center to center). So, I figured that center registration would be useful. But, if your above formula depends on a different registration point then I would need to change this.
Copy link to clipboard
Copied
if you want the distance between the centers, use the function in my last message and leave the dots' reg points in their centers.
Copy link to clipboard
Copied
Thank you!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now