为了保障原创作者在本站发表文章的利益, 并维护本站原创的精神, 特声明: RIAShanghai对有以下任何情况之一的文章将不通知作者并直接进行快意删除:
- 非原创, 或者原创但一文多发;
- 各种形式的广告与吹擂;
- 不符合本站文章格式.
欢迎各位读者监督. 谢谢合作. 另: 作为Adobe正式的UG, 我们将把Adobe不定期分发的软件,书籍及各种纪念品赠送给发文活跃的作者, 共同进步.
Drawing with flex is easy. The class below demonstrates drawing lines, rectangles, gradient fillings, etc.
package
{
import flash.display.GradientType;
import flash.geom.Matrix;
import mx.containers.Canvas;
public class DrawingCanvas extends Canvas
{
public function DrawingCanvas()
{
super();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
// draw canvas border.
graphics.lineStyle(1, 0xcccccc, 1, true);
graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
// draw a line // draw rectangle with round corners. // fill circle. // fill gradient horizontally // fill gradient vertically
graphics.lineStyle(1, 0xff0000, 0.75);
graphics.moveTo(20, 20);
graphics.lineTo(50, 50);
graphics.drawRoundRect(10, 10, 300, 200, 30, 30);
graphics.drawRoundRectComplex(30, 30, 300, 200, 5, 5, 0, 0);
graphics.lineStyle(1, 0x0000ff, 0.5); // set border
graphics.beginFill(0x999999, 0.5); // set fill
graphics.drawCircle(100, 100, 30);
graphics.endFill();
var matrix:Matrix = new Matrix();
matrix.createGradientBox(400, 100);
graphics.lineStyle(1, 0xffffff, 0); // set border
graphics.beginGradientFill(GradientType.LINEAR, [0xff0000, 0x00ff00, 0x0000ff], [1, 1, 1], [0, 60, 120], matrix);
graphics.drawRoundRectComplex(10, 240, 400, 100, 5, 5, 0, 0);
graphics.endFill();
matrix = new Matrix();
matrix.createGradientBox(400, 100, Math.PI * 0.5, 10, 360);
matrix.translate(0, 0);
graphics.beginGradientFill(GradientType.LINEAR, [0xff0000, 0x00ff00, 0x0000ff], [1, 1, 1], [0, 60, 120], matrix);
graphics.drawRoundRectComplex(10, 360, 400, 100, 5, 5, 0, 0);
graphics.endFill();
}
}
}
Output: