Wednesday, May 28, 2008

Sprite in ActionScript 3

A sprite is a new feature introduced in Action Script 3 but unlike MovieClip, Sprite does not contain Timeline. As in Action Script 2, a MovieClip can contain another MoviClip, same is true for Sprite i.e. sprite can contain a children.

Example:
Import flash.display.Sprite
var circle:Sprite=new Sprite();
circle.graphics.beginFill(0xFFCC00);
circle.graphics.drawCircle(200,200,20);
addChild(circle);

In the above example we have imported the class Sprite. In the next line we have declared a new class circle. By using the graphics property we draw a circle of radius 20 at the location 200 & 200. We fill this circle by the yellow color using the beginfill() Method. Finally, the addChild method adds circle instance on the stage.

No comments: