The Point Class
The Point class allows you to create two-dimensional points along the horizontal (x) and vertical (y) axes.It is important when using this class to import it first at the beginning of your script, like this:
To instantiate a new instance of the Point class, use this code as a template:
import flash.geom.Point;
var myPoint:Point = new Point(x, y);
- x
The two-dimensional point on the horizontal axis. - y
The two-dimensional point on the vertical axis.
Example :This example will create an instance of the Point class at coordinate (5,5) and send it to the Output panel:
One other property is not a parameter.
import flash.geom.Point;
var myPoint:Point = new Point(5,5);
trace(myPoint);
//output: (x=5, y=5)
Properties
length
Availability :
FP:8, AS:1.0Generic Template :
myPoint.length;Description :This property will return the length of the line from coordinate (0,0) to the given point.Example: This example will create an instance of the Point class at coordinate (5,5) and send the length from (0,0) to the Output panel:
import flash.geom.Point;
var myPoint:Point = new Point(5,5);
trace(myPoint.length);
//output: 7.07106781186548
Methods
add
Availability :
FP:8, AS:1.0Generic Template :
myPoint.add(point);Parameters:
- point
Another Point object to be added to given point.
Returns :
PointThe new point will be a combination of the Point object calling the method and point .Description: This method will add another point to the given point to create a new point.Example: This example will create an instance of the Point class at coordinate (5,5), add the point (4,4), and TRace the result:
import flash.geom.Point;
var myPoint:Point = new Point(5,5);
var myPoint2:Point = new Point(4,4);
trace(myPoint.add(myPoint2));
//output: (x=9, y=9)
clone
Availability :
FP:8, AS:1.0Generic Template :
myPoint.clone();Returns :
PointThis method will return an exact duplicate of the Point object it is being called on.Description: This method will create an exact copy of the Point object it is being called upon.Example: This example will create a Point object, create a copy, and output that copy:
import flash.geom.Point;
var myPoint:Point = new Point(5,5);
var myPoint2:Point = myPoint.clone();
trace(myPoint2);
//output: (x=5, y=5)
distance
Availability :
FP:8, AS:1.0Generic Template :
Point.distance(point1, point2);Parameters:
- point1
The first point. - point2
The second point.
Returns :
NumberThe distance between the two points in pixels.Description: This method will calculate the distance between two points in two-dimensional space and return it in pixels.Example: This example will create two points and trace the distance between them:
import flash.geom.Point;
var myPoint:Point = new Point(5,5);
var myPoint2:Point = new Point(15,20);
trace(Point.distance(myPoint, myPoint2));
//output: 18.0277563773199
equals
Availability :
FP:8, AS:1.0Generic Template :
myPoint.equals(point);Parameters:
- point
The second Point that myPoint is being compared to.
Returns :
BooleanIf the two points are equal, TRue; otherwise, false.Description: This method will determine if the two points are equal to one another (that is, have the same coordinates) and return a Boolean value.Example: This example will create three points and TRace whether or not they are equal:
import flash.geom.Point;
var myPoint:Point = new Point(5,5);
var myPoint2:Point = new Point(15,20);
var myPoint3:Point = myPoint.clone();
trace(myPoint.equals(myPoint2));
trace(myPoint.equals(myPoint3));
//output: false
// true
interpolate
Availability :
FP:8, AS:1.0Generic Template :
Point.interpolate(point1, point2, lvl);Parameters:
- point1
The first Point. - point2
The second. - lvl
A floating point number between 01 where if 1 is used, point2 will be returned, and if 0 is used, point1 will be returned.
Returns :
PointA point between the two points.Description: This method will determine a Point object that resides between the two points. You can use the lvl parameter to control how near to either point the new point should be.Example: This example will create a point directly between two points:
import flash.geom.Point;
var myPoint:Point = new Point(5,5);
var myPoint2:Point = new Point(15,20);
trace(Point.interpolate(myPoint, myPoint2, .5));
//output: (x=10, y=12.5)
normalize
Availability :
FP:8, AS:1.0Generic Template :
myPoint.normalize(length);Parameters:
- length
The amount to scale the point by.
Description: This method will normalize a point based on the given length .Example: This example will create a normalized point based on the length of 2:
import flash.geom.Point;
var myPoint:Point = new Point(4,10);
myPoint.normalize(2);
trace(myPoint);
//output: (x=0.742781352708207, y=1.85695338177052)
offset
Availability :
FP:8, AS:1.0Generic Template :
myPoint.offset(x, y);Parameters:
- x
The horizontal amount to offset the point by. - y
The vertical amount to offset the point by.
Description: This method will offset a point by the given (x,y) amounts.Example: This example will create a Point and then offset it by (4,4):
import flash.geom.Point;
var myPoint:Point = new Point(5,10);
myPoint.offset(4,4);
trace(myPoint);
//output: (x=9, y=14)
polar
Availability :
FP:8, AS:1.0Generic Template :
Point.polar(length, angle);Parameters:
- length
The length coordinate from the polar pair. - angle
The angle of the polar pair, in radians.
Returns :
PointThe Cartesian point from the polar coordinates.Description: This method will convert polar coordinates to a Cartesian point.Example: This example will create a Cartesian point based on the polar coordinates.
import flash.geom.Point;
var myPoint:Point = Point.polar(10, 45);
trace(myPoint);
//output: (x=5.2532198881773, y=8.50903524534118)
subtract
Availability :
FP:8, AS:1.0Generic Template :
myPoint.subtract(point);Parameters:
- point
The second point to subtract from myPoint .
Returns :
PointThe newly created point based on the difference between the two given points.Description: This method will subtract the second point from the Point calling the method and return a new point.Example: This example will create a Point and subtract a second point (4,4) from it:
import flash.geom.Point;
var myPoint:Point = new Point(5,5);
var myPoint2:Point = new Point(4,4);
trace(myPoint.subtract(myPoint2));
//output: (x=1, y=1)
toString
Availability :
FP:8, AS:1.0Generic Template :
myPoint.toString();Returns :
StringThe coordinates in the form of a string.Description: This method will convert the coordinates into a defined string for output.Example: This example will create a Point and send the coordinates to the Output panel:
import flash.geom.Point;
var myPoint:Point = new Point(5,5);
trace(myPoint.toString());
//output: (x=5, y=5)