Previous Page
Next Page

7.0. Introduction

With ActionScript, you can programmatically draw many display objects such as Shape, Sprite, Button, and MovieClip. Each of these classes has a graphics property that is an instance of the flash.display.Graphics class. The Graphics class defines an API for drawing content programmatically. Most recipes in this chapter discuss how to use the Graphics class API.

Since the Shape, Sprite, Button, and MovieClip classes already define graphics properties that are references to Graphics instances, it is not necessary to construct new Graphics objects. The graphics property for a display object draws within that display object. For example, the following code sets the line style for the Graphics object targeting a sprite called sampleSprite:

sampleSprite.graphics.lineStyle(  );

The Graphics class defines an API for drawing basic lines and simple shapes. However, some common shapes are difficult to draw with the Graphics API. For that reason, the AS3CBLibrary (available at http://www.rightactionscript.com/ascb) includes an ascb.drawing.Pen class. The Pen class is a proxy (a wrapper) for the Graphics class. You can construct a new Pen instance by passing it a reference to the Graphics object you want to target:

var pen:Pen = new Pen(sampleSprite.graphics);

The Pen class proxies requests to all the methods of the Graphics class. That means you can call any of the Graphics methods from the Pen class. In addition, the Pen class defines an API that allows you to more simply draw arcs, ellipses, polygons, stars, and more. The Pen class methods are discussed in the relevant recipes in this chapter.


Previous Page
Next Page
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)