package { import flash.display.*; import flash.text.*; //図形を表示する [SWF(width=240, height=240, backgroundColor=0xCCCCFF)] public class ShapeEx extends Sprite { //コンストラクタ public function ShapeEx() { //ラインの追加 var line:Shape=makeLine(0,0,0,40,0x996633); line.x=25; line.y=5; addChild(line); //ポリラインの追加 var plX:Array=[0,30,10,40,0,5]; var plY:Array=[0,5,20,35,40,5]; var polyline:Shape=makePolyline(plX,plY,0xff3333); polyline.x=55; polyline.y=5; addChild(polyline); //矩形の追加 var rect:Shape=makeRect(40,40,0x55ff55); rect.x=5; rect.y=55; addChild(rect); //角丸矩形の追加 var rrect:Shape=makeRoundRect(40,40,10,0x55ff55); rrect.x=55; rrect.y=55; addChild(rrect); //円の追加 var circle:Shape=makeCircle(20,0xffff55); circle.x=125; circle.y=75; addChild(circle); } //ラインの追加 private function makeLine(x0:int,y0:int,x1:int,y1:int,color:uint):Shape { var line:Shape=new Shape(); line.graphics.lineStyle(0,color); line.graphics.moveTo(x0,y0); line.graphics.lineTo(x1,y1); return line } //ポリラインの追加 private function makePolyline(x:Array,y:Array,color:uint):Shape { var i:int; var line:Shape=new Shape(); line.graphics.lineStyle(0,color); line.graphics.moveTo(x[0],y[0]); for (i=1;i<x.length;i++) { line.graphics.lineTo(x[i],y[i]); } return line; } //矩形の追加 private function makeRect(w:uint,h:uint,color:uint):Shape { var rect:Shape=new Shape(); rect.graphics.beginFill(color); rect.graphics.lineStyle(0,0x000000); rect.graphics.drawRect(0,0,w,h); rect.graphics.endFill(); return rect; } //角丸矩形の追加 private function makeRoundRect(w:uint,h:uint,ew:uint,color:uint):Shape { var rrect:Shape=new Shape(); rrect.graphics.beginFill(color); rrect.graphics.lineStyle(0,0xFF0000); rrect.graphics.drawRoundRect(0,0,w,h,ew); rrect.graphics.endFill(); return rrect; } //円の追加 private function makeCircle(r:uint,color:uint):Shape { var circle:Shape=new Shape(); circle.graphics.beginFill(color); circle.graphics.lineStyle(0,0x000000); circle.graphics.drawCircle(0,0,r); circle.graphics.endFill(); return circle; } } } flash on 2009-10-29