Wonderfl本でお勉強 1-3 その5

by fakestar0826 forked from Wonderfl本でお勉強 1-3 その4 (diff: 36)
お前は基礎からやり直しじゃ!!
* ってな感じでやってきます。
* ASでタイムライン。ループさせた。マウスの軌跡を追うようにする。
♥0 | Line 85 | Modified 2010-04-21 18:49:03 | MIT License
play

ActionScript3 source code

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

/**
 * お前は基礎からやり直しじゃ!!
 * ってな感じでやってきます。
 * ASでタイムライン。ループさせた。マウスの軌跡を追うようにする。
 **/
package {
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    import net.hires.debug.Stats;
    
    [SWF(width = "465", height = "465", frameRate = "30", backgroundColor = "0x000000")]
    import flash.utils.Proxy;
    import flash.geom.Point;
    public class WonderflBook_1_3_5 extends Sprite {
    	
    	    public var c:MovieClip;
    	    public var startP:Number = 0;
    	    public var endP:Number = stage.stageWidth;
    	    public var frameC:int = 0;
    	    public var frameLimit:int = 28;
    	    public var actionFrame:Array;
    	    
    	    public function WonderflBook_1_3_5() {
    	    	    c = new DrawCircle1();
    	    	    addChild(c);
        	    
        	    stage.addEventListener(MouseEvent.MOUSE_DOWN, startMouseRec);
        	    stage.addEventListener(MouseEvent.MOUSE_UP, endMouseRec);
        	    
        	    init();
        	    
        	    start();
        }
        
        public function init():void {
        	    actionFrame = new Array();
        	    var tmpX:Number = startP;
        	    for(var i:int = 0;i < frameLimit;i++)
        	    {
        	    	    tmpX += (endP - tmpX) * 0.2
        	    	    actionFrame[i] = new Point(tmpX, 0);
        	    }	    
        }
        
        public function start():void {
        	    addEventListener(Event.ENTER_FRAME, move);
        }
        public function end():void {
        	    removeEventListener(Event.EXIT_FRAME, move);
        }
        public function move(e:Event):void {
        	    
        	    if(frameC >= frameLimit)
        	    {
        	    	    //end();
        	    	    frameC = 0;
        	    }
        	    else
        	    {
        	    		c.x += (actionFrame[frameC].x - c.x) / 4;
            	    c.y += (actionFrame[frameC].y - c.y) / 4;
        	        frameC++;
        	    }
        }
        
        public function startMouseRec(e:MouseEvent):void{
        	    addEventListener(Event.ENTER_FRAME, doRecMouse);
        }
        
        public function endMouseRec(e:MouseEvent):void{
        	    removeEventListener(Event.ENTER_FRAME, doRecMouse);
        }
        
        public function doRecMouse(e:Event):void{
        	    if(frameC < frameLimit)
        	    {
        	    	    actionFrame[frameC].x = mouseX;
        	    	    actionFrame[frameC].y = mouseY;
        	    }
        }
    }
}

import flash.display.MovieClip;
import flash.events.Event;
class DrawCircle1 extends MovieClip {
	private var centerX:int;
    private var centerY:int;
    private var _r:int = 100;
    
    private var v:Number = 3;
    private var g:Number = 0.98;
    
	public function DrawCircle1() {
		centerX = 10;
		centerY = 10;
		_r = 10;
		graphics.beginFill(0xFF0000);
		graphics.lineStyle(3, 0xFF0000);
    	    graphics.drawCircle(centerX, centerY, _r);
    	    
    	    graphics.endFill();
    	    
    	    
	}
}