In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

curveTo とかベジェとか

package
{
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;

    [SWF(frameRate=30, width=465, height=465, backgroundColor=0xffffff)]

    public class Main extends Sprite
    {
        private var points:Vector.<Sprite>;

        public function Main()
        {
            addEventListener(Event.ADDED_TO_STAGE, initialize);
        }

        private function initialize(evt:Event):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, initialize);

            points = new Vector.<Sprite>();

            var info:TextField = new TextField();
            info.text = "click で作って、 drag で動かす。\n要らなくなったら shift + click で消せるよ。";
            info.autoSize = TextFieldAutoSize.LEFT;
            info.y = stage.stageHeight - info.textHeight;

            addChild(info);

            addEventListener(Event.ENTER_FRAME, step);
            stage.addEventListener(MouseEvent.CLICK, stageClickHandler);
        }

        private function step(evt:Event):void
        {
            var i:uint,
                l:uint,
                g:Graphics,
                ps:Sprite,
                cs:Sprite,
                pp:Point,
                cp:Point;

            g = graphics;
            g.clear();

            l = points.length;
            for (i=1; i<l; i++)
            {
                ps = points[i-1];
                cs = points[i];
                g.lineStyle(1, 0xd8d8d8);
                g.moveTo(ps.x, ps.y);
                g.lineTo(cs.x, cs.y);

                cp = new Point();
                cp.x = ps.x + (cs.x - ps.x) / 2;
                cp.y = ps.y + (cs.y - ps.y) / 2;

                g.lineStyle(1, 0x4c4c4c);
                if (pp)
                {
                    g.moveTo(pp.x, pp.y);
                    g.curveTo(ps.x, ps.y, cp.x, cp.y);
                }
                else
                {
                    g.moveTo(ps.x, ps.y);
                    g.lineTo(cp.x, cp.y);
                }
                pp = cp;
            }
            if (cs)
            {
                g.moveTo(cp.x, cp.y);
                g.lineTo(cs.x, cs.y);
            }
        }

        private function leave(s:Sprite):void
        {
            var i:uint;

            removeChild(s);

            i = points.indexOf(s);
            points.splice(i, 1);

            s.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
            s.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
            s.removeEventListener(MouseEvent.CLICK, clickHandler);
        }

        private function mouseDownHandler(evt:MouseEvent):void
        {
            var s:Sprite = Sprite(evt.target);
            if (evt.shiftKey)
            {
                leave(s);
            }
            else
            {
                s.startDrag();
            }
        }

        private function mouseUpHandler(evt:MouseEvent):void
        {
            stopDrag();
        }

        private function clickHandler(evt:MouseEvent):void
        {
            evt.stopPropagation();
        }

        private function stageClickHandler(evt:MouseEvent):void
        {
            var s:Sprite,
                g:Graphics;

            s = new Sprite();
            s.x = mouseX;
            s.y = mouseY;
            s.buttonMode = true;
            s.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
            s.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
            s.addEventListener(MouseEvent.CLICK, clickHandler);

            g = s.graphics;
            g.beginFill(0x000000);
            g.drawCircle(0, 0, 3);
            g.endFill();

            points.push(s);
            addChild(s);
        }
    }
}