Chapter 25. Drawing with Vectors
In ActionsScript, primitive vectors, lines, and shapes are drawn
via the Graphics class. However,
the Graphics class is never
instantiated directly; instead, each ActionScript class that supports
programmatic vector drawing creates a Graphics instance automatically and provides
access to it via the instance variable graphics
. The display classes that support
vector drawing are Sprite,
MovieClip, and Shape.
Tip
Shape objects consume less memory than Sprite and MovieClip objects. Hence, to conserve memory, vector content should be drawn in Shape objects whenever the containment and interactive capabilities of the Sprite and MovieClip classes are not required.
Graphics Class Overview
As shown in Table 25-1, the Graphics class’s drawing tools can be broken down into five general categories: drawing lines, drawing shapes (also known as fills), defining line styles, moving the drawing pen, and removing graphics.
Purpose | Graphics method |
Drawing lines | curveTo( ), lineTo( ) |
Drawing shapes | beginBitmapFill( ), beginFill( ), beginGradientFill( ), drawCircle( ), drawEllipse( ), drawRect( ), drawRoundRect( ), drawRoundRectComplex( ), endFill( ) |
Defining line styles | lineGradientStyle( ), lineStyle( ) |
Moving the drawing pen | moveTo( ) |
Removing graphics | clear( ) |
Conceptually, lines and curves are drawn in ActionScript by a theoretical “drawing pen.” For all new Sprite, MovieClip, and Shape objects, the pen starts out at position (0,0). As lines ...
Get Essential ActionScript 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.