13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Display programming<br />

The GeometricSprite class and its subclasses<br />

Each display object the user can add to the canvas is an instance of one of the following subclasses of the<br />

GeometricSprite class:<br />

CircleSprite<br />

SquareSprite<br />

TriangleSprite<br />

The GeometricSprite class ext<strong>en</strong>ds the flash.display.Sprite class:<br />

public class GeometricSprite ext<strong>en</strong>ds Sprite<br />

The GeometricSprite class includes a number of properties common to all GeometricSprite objects. These are set in<br />

the constructor function based on parameters passed to the function. For example:<br />

this.size = size;<br />

this.lineColor = lColor;<br />

this.fillColor = fColor;<br />

The geometricShape property of the GeometricSprite class defines an IGeometricShape interface, which defines the<br />

mathematical properties, but not the visual properties, of the shape. The classes that implem<strong>en</strong>t the IGeometricShape<br />

interface are defined in the GeometricShapes sample application described in Learning ActionScript 3.0.<br />

The GeometricSprite class defines the drawShape() method, which is further refined in the override definitions in<br />

each subclass of GeometricSprite. For more information, see the “Adding display objects to the canvas” section, which<br />

follows.<br />

The GeometricSprite class also provides the following methods:<br />

The onMouseDown() and onMouseUp() methods, which are described in “Clicking and dragging display objects”<br />

on page 207<br />

The showSelected() and hideSelected() methods, which are described in “Clicking and dragging display<br />

objects” on page 207<br />

Adding display objects to the canvas<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

Wh<strong>en</strong> the user clicks the Add Shape button, the application calls the addShape() method of the DrawingCanvas class.<br />

It instantiates a new GeometricSprite by calling the appropriate constructor function of one of the GeometricSprite<br />

subclasses, as the following example shows:<br />

Last updated 6/6/2012<br />

205

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!