Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 191

Programming actionscript 3.0
Table of Contents

Advertisement

Adding display objects to the canvas
When the user clicks the Add Shape button, the application calls the
the DrawingCanvas class. It instantiates a new GeometricSprite by calling the appropriate
constructor function of one of the GeometricSprite subclasses, as the following example
shows:
public function addShape(shapeName:String, len:Number):void
{
var newShape:GeometricSprite;
switch (shapeName)
{
case "Triangle":
newShape = new TriangleSprite(len);
break;
case "Square":
newShape = new SquareSprite(len);
break;
case "Circle":
newShape = new CircleSprite(len);
break;
}
newShape.alpha = 0.8;
this.addChild(newShape);
}
Each constructor method calls the
of the class (inherited from the Sprite class) to draw the appropriate vector graphic. For
example, the
drawShape()
this.graphics.clear();
this.graphics.lineStyle(1.0, this.lineColor, 1.0);
this.graphics.beginFill(this.fillColor, 1.0);
var radius:Number = this.size / 2;
this.graphics.drawCircle(radius, radius, radius);
The second to last line of the
object (inherited from the DisplayObject class), so that each display object added to the
canvas is slightly transparent, letting the user see the objects behind it.
The final line of the
addChild()
instance of the DrawingCanvas class, which is already on the display list. This causes the new
display object to appear on the Stage.
drawShape()
method of the CircleSprite class includes the following code:
function sets the
addShape()
method adds the new display object to the child list of the
addShape()
method, which uses the
property of the display
alpha
Example: SpriteArranger
method of
property
graphics
191

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents