本文是ActionScript3 Tips and Tricks系列阅读笔记之一Graphics Object and the Drawing API,这里是原文地址

图形对象和绘图API

就像ActionScript1和2一样,ActionScript3也有绘图API,你可以使用它们在影片剪辑和sprite对象中绘制矢量线条或图形。使用ActionScript3,绘图API总是在显示对象(例如影片剪辑、sprite等等)的graphics属性(flash.display.Graphics)中使用。graphics属性表现为绘图API绘制出的一个动态层。就像以前一样,这个动态层位于绘图目标对象的所有的子对象之下。在ActionScript3中,提供了一些新的方法让你绘制矩形、圆形以及圆角矩形变得更加容易。它们包括:

  • 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

范例:

1
2
3
4
5
6
// 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);

原文如下:

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:

以下内容同上。

留言