Calculate distance between 2 points in AS3

December 17, 2009

So, I’ve had to do this on a few occasions now, and I have found the most efficient ( well in terms of lines of code ) to do this in Actionscript 3.

Before you can use this, you must have the x,y positions of the the 2 objects you want to calculate the distance between ( of course ).

The line of code I ended up using looks like this

var distance:Number = Point.distance(new Point(objectA.x, objectA.y),
                                     new Point(objectB.x, objectB.y));

There may be ways to extract the point object right out of an objects, if so , let me know. But this definately works.. now I can move on  to finishing my app : )

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: