▼ActionScript 3.0メモ▼
図形の表示


図形を表示するFlashを作成する。

ソースコード
ShapeEx.as
package {
    import flash.display.*;
    
    //図形の表示
    [SWF(width=240, height=240, backgroundColor=0xFFFFFF)]
    public class ShapeEx extends Sprite {
        //コンストラクタ
        public function ShapeEx() {
            //ラインの追加
            var line:Shape = makeLine(0, 0, 0, 40, 0xff3333);
            line.x = 25;
            line.y = 5;
            addChild(line);

            //ポリラインの追加
            var plX:Array = [0, 30, 10, 40, 0];
            var plY:Array = [0, 5, 20, 35, 40];
            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, 20, 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, 0x000000);
            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;
        }        
    }
}



−戻る−