Geometry may be a subject many people try to get through in school while retaining as little as possible, but a little geometry knowledge can be a powerful tool in ActionScript™.
The flash.geom package contains classes that define geometric objects such as points, rectangles, and transformation matrixes. These classes don't necessarily provide functionality by themselves; however, they are used to define the properties of objects that are used in other classes.
All the geometry classes are based around the notion that locations on the screen are represented as a two-dimensional plane. The screen is treated like a flat graph with a horizontal (x) axis and a vertical (y) axis. Any location (or point) on the screen can be represented as a pair of x and y values--the coordinates of that location.
Every display object, include the Stage, has its own coordinate space--essentially its own graph for plotting the locations of child display objects, drawings, and so forth. Commonly, the origin (the place with the coordinate 0, 0 where the x and y axes meet) is placed at the top-left corner of the display object. While this is always true for the Stage, it is not necessarily true for any other display object. As in standard two-dimensional coordinate systems, values on the x axis get bigger going toward the right, and smaller going toward the left--for locations to the left of the origin, the x coordinate is negative. However, contrary to traditional coordinate systems, in ActionScript values on the y axis get bigger going down and smaller going up the screen (with values above the origin having a negative y coordinate). Since the top-left corner of the Stage is the origin of its coordinate space, any object on the Stage will have an x coordinate greater than 0 and smaller than the Stage width, and will have a y coordinate larger than 0 and smaller than the Stage height.
You can use Point class instances to represent individual points in a coordinate space. You can create a Rectangle instance to represent a rectangular region in a coordinate space. For advanced users, you can use a Matrix instance to apply multiple or complex transformations to a display object. Many simple transformations, such as rotation, position, and scale changes, can be applied directly to a display object using that object's properties. For more information on applying transformations using display object properties, see Manipulating display objects.
The following tasks are things you'll likely want to accomplish using the geometry classes in ActionScript:
The following reference list contains important terms that you will encounter in this chapter: