Section 7.0. Introduction


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.




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net