Object | +-flash.geom.Point public class Point extends Object The Point class represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis. The following code creates a point at (0,0): var myPoint:Point = new Point(); Availability: ActionScript 1.0; Flash Player 8 Property summary
Properties inherited from class Object
Constructor summary
Method summary
Methods inherited from class Object
add (Point.add method)public add(v:Point) : Point Adds the coordinates of another point to the coordinates of this point to create a new point. Availability: ActionScript 1.0; Flash Player 8 Parameters v:flash.geom.Point - The point to be added. Returns flash.geom.Point- The new point. Example The following example creates a Point object resultPoint by adding point_2 to point_1. import flash.geom.Point; var point_1:Point = new Point(4, 8); var point_2:Point = new Point(1, 2); var resultPoint:Point = point_1.add(point_2); trace(resultPoint.toString()); // (x=5, y=10) clone (Point.clone method)public clone() : Point Creates a copy of this Point object. Availability: ActionScript 1.0; Flash Player 8 Returns flash.geom.Point - The new Point object. Example The following example creates a copy of the Point object called clonedPoint from the values found in the myPoint object. The clonedPoint object contains all of the values from myPoint, but it is not the same object. import flash.geom.Point; var myPoint:Point = new Point(1, 2); var clonedPoint:Point = myPoint.clone(); trace(clonedPoint.x); // 1 trace(clonedPoint.y); // 2 trace(myPoint.equals(clonedPoint)); // true trace(myPoint === clonedPoint); // false distance (Point.distance method)public static distance(pt1:Point, pt2:Point) : Number Returns the distance between pt1 and pt2. Availability: ActionScript 1.0; Flash Player 8 Parameters pt1:flash.geom.Point- The first point. pt2:flash.geom.Point- The second point. Returns Number - The distance between the first and second points. Example The following example creates point_1 and point_2, then determines the distance between them (distanceBetween). import flash.geom.Point; var point_1:Point = new Point(-5, 0); var point_2:Point = new Point(5, 0); var distanceBetween:Number = Point.distance(point_1, point_2); trace(distanceBetween); // 10 equals (Point.equals method)public equals(toCompare:Object) : Boolean Determines whether two points are equal. Two points are equal if they have the same x and y values. Availability: ActionScript 1.0; Flash Player 8 Parameters toCompare:Object - The point to be compared. Returns Boolean - If the object is equal to this Point object, TRue; if it is not equal, false. Example The following example determines whether the values of one point are equal to the values of another point. If the objects are the same, equals() does not return the same result that the strict equality operator (===) does. import flash.geom.Point; var point_1:Point = new Point(1, 2); var point_2:Point = new Point(1, 2); var point_3:Point = new Point(4, 8); trace(point_1.equals(point_2)); // true trace(point_1.equals(point_3)); // false trace(point_1 === point_2); // false trace(point_1 === point_3); // false interpolate (Point.interpolate method)public static interpolate(pt1:Point, pt2:Point, f:Number) : Point Determines a point between two specified points. Availability: ActionScript 1.0; Flash Player 8 Parameters pt1:flash.geom.Point- The first point. pt2:flash.geom.Point- The second point. f:Number - The level of interpolation between the two points. Indicates where the new point will be, along the line between pt1 and pt2. If f=0, pt1 is returned; if f=1, pt2 is returned. Returns flash.geom.Point - The new, interpolated point. Example The following example locates the interpolated point (interpolatedPoint) half way (50%) between point_1 and point_2. import flash.geom.Point; var point_1:Point = new Point(-100, -100); var point_2:Point = new Point(50, 50); var interpolatedPoint:Point = Point.interpolate(point_1, point_2, .5); trace(interpolatedPoint.toString()); // (x=-25, y=-25) length (Point.length property)public length : Number The length of the line segment from (0,0) to this point. Availability: ActionScript 1.0; Flash Player 8 Example The following example creates a Point object, myPoint, and determines the length of a line from (0, 0) to that Point. import flash.geom.Point; var myPoint:Point = new Point(3,4); trace(myPoint.length); // 5 See also polar (Point.polar method) normalize (Point.normalize method)public normalize(length:Number) : Void Scales the line segment between (0,0) and the current point to a set length. Availability: ActionScript 1.0; Flash Player 8 Parameters length:Number - The scaling value. For example, if the current point is (0,5), and you normalize it to 1, the point returned is at (0,1). Example The following example extends the length of the normalizedPoint object from 5 to 10. import flash.geom.Point; var normalizedPoint:Point = new Point(3, 4); trace(normalizedPoint.length); // 5 trace(normalizedPoint.toString()); // (x=3, y=4) normalizedPoint.normalize(10); trace(normalizedPoint.length); // 10 trace(normalizedPoint.toString()); // (x=6, y=8) See also length (Point.length property) offset (Point.offset method)public offset(dx:Number, dy:Number) : Void Offsets the Point object by the specified amount. The value of dx is added to the original value of x to create the new x value. The value of dy is added to the original value of y to create the new y value. Availability: ActionScript 1.0; Flash Player 8 Parameters dx:Number - The amount by which to offset the horizontal coordinate, x. dy:Number - The amount by which to offset the vertical coordinate, y. Example The following example offsets a point's position by specified x and y amounts. import flash.geom.Point; var myPoint:Point = new Point(1, 2); trace(myPoint.toString()); // (x=1, y=2) myPoint.offset(4, 8); trace(myPoint.toString()); // (x=5, y=10) See also add (Point.add method) Point constructorpublic Point(x:Number, y:Number) Creates a new point. If you pass no parameters to this method, a point is created at (0,0). Availability: ActionScript 1.0; Flash Player 8 Parameters x:Number - The horizontal coordinate. The default value is 0. y:Number - The vertical coordinate. The default value is 0. Example The first example creates a Point object point_1 with the default constructor. import flash.geom.Point; var point_1:Point = new Point(); trace(point_1.x); // 0 trace(point_1.y); // 0 The second example creates a Point object point_2 with the coordinates x = 1 and y = 2. import flash.geom.Point; var point_2:Point = new Point(1, 2); trace(point_2.x); // 1 trace(point_2.y); // 2 polar (Point.polar method)public static polar(len:Number, angle:Number) : Point Converts a pair of polar coordinates to a cartesian point coordinate. Availability: ActionScript 1.0; Flash Player 8 Parameters len:Number - The length coordinate of the polar pair. angle:Number - The angle, in radians, of the polar pair. Returns flash.geom.Point - The cartesian point. Example The following example creates a Point object cartesianPoint from the value of angleInRadians and a line length of 5. The angleInRadians value equal to Math.atan(3/4) is used because of the characteristics of right triangles with sides that have ratios of 3:4:5. import flash.geom.Point; var len:Number = 5; var angleInRadians:Number = Math.atan(3/4); var cartesianPoint:Point = Point.polar(len, angleInRadians); trace(cartesianPoint.toString()); // (x=4, y=3) When computers work with transcendental numbers such as pi, some round-off error occurs because floating-point arithmetic has only finite precision. When you use Math.PI, consider using the Math.round() function, as shown in the following example. import flash.geom.Point; var len:Number = 10; var angleInRadians:Number = Math.PI; var cartesianPoint:Point = Point.polar(len, angleInRadians); trace(cartesianPoint.toString()); // should be (x=-10, y=0), but is (x=-10, y=1.22460635382238e-15) trace(Math.round(cartesianPoint.y)); // 0 See also length (Point.length property), round (Math.round method) subtract (Point.subtract method)public subtract(v:Point) : Point Subtracts the coordinates of another point from the coordinates of this point to create a new point. Availability: ActionScript 1.0; Flash Player 8 Parameters v:flash.geom.Point - The point to be subtracted. Returns flash.geom.Point- The new point. Example The following example creates point_3 by subtracting point_2 from point_1. import flash.geom.Point; var point_1:Point = new Point(4, 8); var point_2:Point = new Point(1, 2); var resultPoint:Point = point_1.subtract(point_2); trace(resultPoint.toString()); // (x=3, y=6) toString (Point.toString method)public toString() : String Returns a string that contains the values of the x and y coordinates. It has the form (x, y), so a Point at 23,17 would report "(x=23, y=17)". Availability: ActionScript 1.0; Flash Player 8 Returns String- A string. Example The following example creates a point and converts its values to a string in the format (x=x, y=y). import flash.geom.Point; var myPoint:Point = new Point(1, 2); trace("myPoint: " + myPoint.toString()); // (x=1, y=2) x (Point.x property)public x : Number The horizontal coordinate of the point. The default value is 0. Availability: ActionScript 1.0; Flash Player 8 Example The following example creates a Point object myPoint and sets the x coordinate value. import flash.geom.Point; var myPoint:Point = new Point(); trace(myPoint.x); // 0 myPoint.x = 5; trace(myPoint.x); // 5 y (Point.y property)public y : Number The vertical coordinate of the point. The default value is 0. Availability: ActionScript 1.0; Flash Player 8 Example The following example creates a Point object myPoint and sets the y coordinate value. import flash.geom.Point; var myPoint:Point = new Point(); trace(myPoint.y); // 0 myPoint.y = 5; trace(myPoint.y); // 5 |