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

TweenGesture2

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

// forked from yd_niku's TweenGesture
// forked from HaraMakoto's Tweenerでミサイルぽく移動
package {
    import caurina.transitions.Tweener;
    import caurina.transitions.properties.CurveModifiers;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Shape;
    import flash.filters.BlurFilter;
    import flash.geom.ColorTransform;
    
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    
    [SWF(width=465, height=465, backgroundColor=0, frameRate=60)]
    public class TweenGesture extends Sprite {
        CurveModifiers.init();
        private var moveObj:Sprite;
        
        private var canvas:BitmapData;
        private var locusLayer:Shape;
        private var moverLayer:Sprite;
        private var trans:String = "linear";
        
        public function TweenGesture () {
            addEventListener(Event.ADDED_TO_STAGE, init );
        }
        
        private function init(e:Event):void {
            removeEventListener(Event.ADDED_TO_STAGE, init );
            stage.addEventListener(MouseEvent.MOUSE_DOWN, startLine );
            
            canvas = new BitmapData( 465, 465, false, 0x00 );
            addChild( new Bitmap( canvas ) );
            
            locusLayer = new Shape();
            addChild( locusLayer );
            
            moverLayer = new Sprite();
            addChild( moverLayer );
            
            moveObj = new Ball();
            moverLayer.addChild( moveObj );
            
            stage.addEventListener( Event.ENTER_FRAME, updateCanvas );
        }
        
        private function startLine(e:MouseEvent):void {
            stage.addEventListener( Event.ENTER_FRAME, drawLine );
            stage.addEventListener( MouseEvent.MOUSE_UP, fire );
            
            locusLayer.graphics.clear();
            locusLayer.graphics.lineStyle( 0, 0x006600, 0.6 );
            locusLayer.graphics.moveTo( mouseX, mouseY );
            
            _moveCount = 0;
            _points = [ new Point(mouseX,mouseY) ];
        }
        private var _points:Array = [];
        private var _moveCount:int = 0;
        private function drawLine(e:Event):void {
            locusLayer.graphics.lineTo( mouseX, mouseY );
            
            if( ( _moveCount++) % 5== 0 ) {
                locusLayer.graphics.beginFill( 0x000066, 0.5 );
                locusLayer.graphics.drawCircle( mouseX, mouseY, 2 );
                locusLayer.graphics.endFill();
                
                _points.push( new Point( mouseX, mouseY ) );
            }
        }
        private function fire( e:Event ):void {
            stage.removeEventListener( Event.ENTER_FRAME, drawLine );
            var bz:Array = [];
            for( var i:int=0, l:int=_points.length; i<l; ++i ) {
                var p0:Point = _points[i];
                var p1:Point = _points[i+1];
                
                bz[i] = { x: p0.x, y:p0.y };
                //bz[i] = { x:(p1.x -p0.x)*0.5+p0.x, y:(p1.y -p0.y)*0.5+p0.y };
            }
            moveObj.x = _points[0].x;
            moveObj.y = _points[0].y;
            Tweener.addTween( moveObj,
             {x:mouseX, y:mouseY, _bezier:bz, time:Math.max(1, _points.length/6 ), transition:trans });
        }
        
        private var blur:BlurFilter = new BlurFilter();
        private var ctf:ColorTransform = new ColorTransform( 0.9, 0.9, 0.9, 1 );
        private var p:Point = new Point();
        private function updateCanvas(e:Event):void {
            //canvas.applyFilter( canvas, canvas.rect, p, blur );
            canvas.colorTransform( canvas.rect, ctf );
            canvas.draw( moverLayer );
        }
    }
}

import flash.display.Sprite;
class Ball extends Sprite {
    public function Ball( color:uint = 0xFFFFFF ) {
        graphics.beginFill(color);
        graphics.drawCircle(0,0,4);
        graphics.endFill();
    }
}