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

forked from: マウスに一定距離まで引き寄せられる点

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

// forked from okoi's マウスに一定距離まで引き寄せられる点
package {
    	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;

    public class FlashTest extends MovieClip {
    		private	static const NUM_X:int = 20;
		private static const NUM_Y:int = 20;
		public	static const POINT_SPAN:int = 20;
		private	var	pointList:Array = new Array();
		private var burstList:Array = new Array();

    	
        public function FlashTest() {
            // write as3 code here..
            if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
		public	function init(event:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			for ( var i:int = 0; i < NUM_X * NUM_Y; i++ )
			{
				var p:PathPoint = new PathPoint();
				p.Init( int(i % NUM_X) * POINT_SPAN, int(i / NUM_X) * POINT_SPAN );
				pointList.push( p );
				addChild( p );
			}
			
			graphics.beginFill(0x000000);
			graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
		
			addEventListener(Event.ENTER_FRAME, EnterFrame );
			stage.addEventListener( MouseEvent.MOUSE_DOWN, ClickMouse );
			
		}
		public	function EnterFrame(event:Event):void 
		{
			var i:int = 0;
			//	爆発エネルギーの処理
			for ( i = burstList.length - 1; i >= 0; i-- )
			{
				if ( !burstList[i].Run() )
				{
					burstList.slice( i, i );
				}else
				{
					for ( var j:int = 0; j < pointList.length; j++ )	pointList[j].BurstEffect( burstList[i].x, burstList[i].y, burstList[i].R );
				}
			}
			
		}
		
		public	function ClickMouse(event:MouseEvent):void
		{
			var burst:Burst = new Burst();
			burst.Start(stage.mouseX, stage.mouseY);
			burstList.push( burst );
		}		        
    }
}
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
import flash.display.MovieClip;
import flash.events.Event;

class PathPoint extends MovieClip {
	//	基本座標
	public	var	defX:Number;
	public	var defY:Number;
	//	影響値
	public	var	effectX:Number;
	public	var effectY:Number;

	
	public	function PathPoint():void 
	{
		super();
		
		graphics.beginFill(0xFFFFFF);
		graphics.drawCircle(0, 0, 5);
	}
	
	public	function Init(_x:Number, _y:Number):void 
	{
		this.x = _x;
		this.y = _y;
		defX = _x;
		defY = _y;
		effectX = 0;
		effectY = 0;

		addEventListener( Event.ENTER_FRAME, EnterFrame );
	}
	
	public	function EnterFrame(event:Event):void 
	{
		if ( !stage ) return;
		
		var mX:int = stage.mouseX;
		var mY:int = stage.mouseY;
		
		var len:Number = Math.sqrt( (mX - defX) * (mX - defX) + (mY - defY) * (mY - defY) );		
		var r:Number = Math.atan2( (mY - defY), (mX - defX) );
		
		var targetX:Number = defX + Math.cos( r ) * 10;
		var targetY:Number = defY + Math.sin( r ) * 10;
		
		targetX += effectX;
		targetY += effectY;
		
		this.x += (targetX - this.x) / 10;
		this.y += (targetY - this.y) / 10;
		
		//	干渉されたエネルギーは徐々に減衰
		effectX -= effectX / 5;
		effectY -= effectY / 5;		
	}
	
	public	function BurstEffect(bX:int, bY:int, bR:Number):void 
	{
		//	爆発地点からここまでの距離
		var len:Number = Math.sqrt( (defX - bX) * (defX - bX) + (defY - bY) * (defY - bY) );
		//	爆発地点からここまでのベクトルを正規化
		var nX:Number = (defX - bX) / len;
		var nY:Number = (defY - bY) / len;
		
		//	
		var rLen:Number = len - bR;
		if ( rLen >= 0 )
		{
			if ( rLen < 50 )
			{
				effectX += nX*2;
				effectY += nY*2;
			}
		}
	}	
}
/////////////////////////////////////////////////////////////////
//	クリックした時に発生する円形エネルギークラス
class Burst extends MovieClip {
	
	var R:Number = 0;
	
	public	function Burst()
	{
		super();
		
		addEventListener( Event.REMOVED_FROM_STAGE, Term );
	}
	
	public	function Term(event:Event):void 
	{
		removeEventListener( Event.REMOVED_FROM_STAGE, Term );
	}
	
	public	function Start(_x:int, _y:int):void
	{
		this.x = _x;
		this.y = _y;
		R = 0;
	}
	
	public	function Run():Boolean 
	{
		R += 5;
		
		if ( R >= 500 )
		{
			return	false;
		}
		return	true;
	}
	
}