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

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

Get Adobe Flash player
by okoi 11 Mar 2010
/**
 * Copyright okoi ( http://wonderfl.net/user/okoi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6puD
 */

package {
    	import flash.display.MovieClip;
	import flash.events.Event;

    public class FlashTest extends MovieClip {
    		private	static const NUM_X:int = 10;
		private static const NUM_Y:int = 10;
		private	var	pointList: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) * 40, int(i / NUM_X) * 40 );
				addChild( p );
			}
			
			graphics.beginFill(0x000000);
			graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
			
		}        
    }
}
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
import flash.display.MovieClip;
import flash.events.Event;

class PathPoint extends MovieClip {
	//	基本座標
	public	var	defX:Number;
	public	var defY:Number;
	//	影響値
	public	var	effect: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;
		
		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 powerRate:Number = (len / 40);
		if ( powerRate > 1 ) powerRate = 1;
		var r:Number = Math.atan2( (mY - defY), (mX - defX) );
		
		var targetX:Number = defX + Math.cos( r ) * 10 * powerRate;
		var targetY:Number = defY + Math.sin( r ) * 10 * powerRate;
		
		this.x += (targetX - this.x) / 10;
		this.y += (targetY - this.y) / 10;
	}
}