O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Table 25-1. Graphics class overview

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required