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

[test] graphics.cubicCurveTo()

FP11から用意された(と思われる)3次ベジェ曲線関数のテスト
Get Adobe Flash player
by geko 09 Sep 2012

    Tags

    Embed
/**
 * Copyright geko ( http://wonderfl.net/user/geko )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/knfC
 */

package {
    import flash.text.TextField;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    
    public class FlashTest extends Sprite {
        private var a1:Sprite,a2:Sprite,c1:Sprite,c2:Sprite;
        
        public function FlashTest() {
            a1=setPoint(new Sprite(),80,260,"anchor 1",6.5,0xC85833);
            a2=setPoint(new Sprite(),320,300,"anchor 2",6.5,0xC85833);
            c1=setPoint(new Sprite(),120,80,"control 1");
            c2=setPoint(new Sprite(),300,160,"control 2");
            
            addEventListener(Event.ENTER_FRAME,update);
        }
        
        private function setPoint(t:Sprite,_x:Number,_y:Number,_l:String,_r:uint=5,_c:uint=0x3358C8):Sprite{
            t.x=_x, t.y=_y;
            t.graphics.beginFill(_c);
            t.graphics.drawCircle(0,0,_r);
            t.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
            t.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
            this.addChild(t);
            
            var label:TextField = new TextField();
            label.text = _l;
            label.mouseEnabled = false;
            t.addChild(label);
            return t;
        }
        private function mouseDown(e:MouseEvent):void{
            var t:Sprite = e.currentTarget as Sprite;
            t.startDrag();
        }
        private function mouseUp(e:MouseEvent):void{
            var t:Sprite = e.currentTarget as Sprite;
            t.stopDrag();
        }
        
        public function update(e:Event):void{
            this.graphics.clear();
            
            // draw auxilliary lines
            this.graphics.lineStyle(1,0xCCCCCC);
            this.graphics.moveTo(a1.x,a1.y);
            this.graphics.lineTo(c1.x,c1.y);
            this.graphics.moveTo(a2.x,a2.y);
            this.graphics.lineTo(c2.x,c2.y);
            this.graphics.lineStyle(2,0xC85833);
            
            // draw cubicCurve
            this.graphics.moveTo(a1.x,a1.y);
            this.graphics.cubicCurveTo(c1.x,c1.y,c2.x,c2.y,a2.x,a2.y);
        }
    }
}