The Point ClassThe 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: import flash.geom.Point; To instantiate a new instance of the Point class, use this code as a template: var myPoint:Point = new Point(x, y);
Example: This example will create an instance of the Point class at coordinate (5,5) and send it to the Output panel: import flash.geom.Point; var myPoint:Point = new Point(5,5); trace(myPoint); //output: (x=5, y=5) One other property is not a parameter. PropertieslengthAvailability: FP:8, AS:1.0 Generic 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 MethodsaddAvailability: FP:8, AS:1.0 Generic Template: myPoint.add(point); Parameters:
Returns: Point The 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) cloneAvailability: FP:8, AS:1.0 Generic Template: myPoint.clone(); Returns: Point This 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) distanceAvailability: FP:8, AS:1.0 Generic Template: Point.distance(point1, point2); Parameters:
Returns: Number The 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 equalsAvailability: FP:8, AS:1.0 Generic Template: myPoint.equals(point); Parameters:
Returns: Boolean If 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 interpolateAvailability: FP:8, AS:1.0 Generic Template: Point.interpolate(point1, point2, lvl); Parameters:
Returns: Point A 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) normalizeAvailability: FP:8, AS:1.0 Generic Template: myPoint.normalize(length); Parameters:
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) offsetAvailability: FP:8, AS:1.0 Generic Template: myPoint.offset(x, y); Parameters:
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) polarAvailability: FP:8, AS:1.0 Generic Template: Point.polar(length, angle); Parameters:
Returns: Point The 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) subtractAvailability: FP:8, AS:1.0 Generic Template: myPoint.subtract(point); Parameters:
Returns: Point The 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) toStringAvailability: FP:8, AS:1.0 Generic Template: myPoint.toString(); Returns: String The 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) |