moock.org is supported in part by


June 05, 2007

Chapter 25, Paragraphs 1-5, Essential ActionScript 3.0

Here are the first 5 paragraphs of Chapter 25 of Essential ActionScript 3.0

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.

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.

Table 25-1. Graphics class overview

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 and curves are drawn (via lineTo() and curveTo()), the pen moves around the object’s coordinate space, resting at the end point of the last line or curve drawn. The pen’s current position always indicates the starting point of the next line or curve to be drawn. To arbitrarily set the starting point of a line or curve, we use the moveTo() method, which “picks up” the drawing pen and moves it to a new position without drawing a line to the specified point.

Posted by moock at June 5, 2007 10:24 PM