2007年3月26日星期一

Graphics Object and the Drawing API

Graphics Object and the Drawing API

Like ActionScript 1 and 2, ActionScript 3 also has a drawing API that allows you to draw vector lines and shapes dynamically in movie clips and sprites. With ActionScript 3, however, the drawing API is now used off of an object within display objects (movie clips, sprites, etc.) defined as graphics (flash.display.Graphics). This graphics property represents the dynamic drawing layer where drawing API drawings exist. Like before, it is placed below all children of the target object. Also, in ActionScript 3, you have new methods that help you more easily create rectangles, circles, and even rounded rectangles. These include:

  • drawCircle(x:Number, y:Number, radius:Number):void
  • drawEllipse(x:Number, y:Number, width:Number, height:Number):void
  • drawRect(x:Number, y:Number, width:Number, height:Number):void
  • drawRoundRect(x:Number, y:Number, width:Number, height:Number, ellipseWidth:Number, ellipseHeight:Number):void


Example:

ActionScript Code:

// draw a blue rounded rectangle:
var square:Sprite = new Sprite();
square.
graphics.beginFill(0xFF);
square.
graphics.drawRoundRect(0, 0, 100, 50, 10, 10);
square.
graphics.endFill();
addChild(square);

0 评论: