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: 布的ななにか・。(マウスで押したりできます・。)

// forked from shun_channel's 布的ななにか・。(マウスで押したりできます・。)

package{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.display.MovieClip;
	import flash.geom.Rectangle;
	import flash.geom.Point;
	[SWF(width=465, height=465, backgroundColor=0x0, frameRate=60)]
	public class MouseReaction extends Sprite{
		private var starList:Array;
		private var row:uint = 30;
		private var col:uint = 30;
		private var maxDis:Number;
		private var area:Rectangle;
		private var power:Number = -1;
		private var spring:Number = 0.02;
		private var friction:Number = 0.9;
		/*------------
		最初にリストを用意する。
		等間隔で並べて生きます。
		最後に、左上から一個ずつ格納していきます。
		public function Rectangle(x:Number = 0, y:Number = 0, width:Number = 0, height:Number = 0) 
		また、マウスの動きに反応をするように設定。
		-----------------*/
		public function MouseReaction(){
			starList = new Array();
			var space:Number = 8;
			for( var i:int = 0;i<row;i++){
				for(var j:int = 0;j<col;j++){
					var star:StarMC = new StarMC();
					var ofsx:Number = (stage.stageWidth - space*(row - 1))/2;
					var ofsy:Number = (stage.stageHeight - space*(col-1))/2;
					star.x0 = space * i + ofsx;
					star.y0 = space*j + ofsy;
					star.x = star.x0;
					star.y = star.y0;
					star.height = 3
					star.width = 3
					star.vx = 0;
					star.vy = 0;
					starList.push(star);
					addChild(star);
				}
			}
			maxDis = 100;
			area = new Rectangle( 50,50,stage.stageWidth - 100,stage.stageHeight - 100);
			stage.addEventListener(MouseEvent.MOUSE_DOWN,onMousedown);
			stage.addEventListener(MouseEvent.MOUSE_UP,onMouseup);
			stage.addEventListener(Event.ENTER_FRAME,onEnterframe);
		}
		private function onMousedown(evt:MouseEvent):void{
			power = 1;
		}
		private function onMouseup(evt:MouseEvent):void{
			power = -1;
		}
		
		/*----------------------
		マウスとの位置関係についてなど常に動作している部分の事。
		まず、マウスと対象の距離の関係をとります。
		マウスのいる位置の指定をしている。
		距離と、角度を取得して角度の方向によるような形。
		
		-----------------------*/
		private function onEnterframe(evt:Event):void{
			var msx:Number = mouseX;
			var msy:Number = mouseY;
			var mousePoint:Point = new Point(msx,msy);
			
			var star:StarMC;
			var starPoint:Point;
			var dis:Number;
			var k:Number;
			var d:Number;
			var rad:Number;
			var dx:Number;
			var dy:Number;
			var frm:uint;
			
			for(var i:int = 0; i < starList.length;i++){
				star = starList[i];
				starPoint = new Point(star.x0,star.y0);
				dis = Point.distance( mousePoint,starPoint);
					if(dis < maxDis && area.contains(msx,msy)){
						k = (maxDis - dis)/maxDis;
						d = dis * k * power/2;
						rad = Math.atan2(msy - star.y0,msx - star.x0);
						dx = star.x0 + Math.cos(rad)*d;
						dy = star.y0 + Math.sin(rad)*d;
					}else{
						dx = star.x0;
						dy = star.y0;
					}
					starPosition(star,dx,dy);
			}
		}
		private function starPosition(star:StarMC,dx:Number,dy:Number):void{
			star.vx += (dx - star.x)*spring;
			star.vx *= friction;
			star.x += star.vx;
			
			star.vy += (dy-star.y)*spring;
			star.vy *= friction;
			star.y += star.vy;
		}
	}
}
import flash.display.Sprite;        
 class StarMC extends Sprite{
     public var x0:Number;
     public var vx:Number;
     public var y0:Number;
     public var vy:Number;
     public function StarMC(){
         var circleSp:Sprite = new Sprite();
         circleSp.graphics.beginFill(Math.random()*0xffffff);
         circleSp.graphics.drawCircle(0,0,200);
         addChild(circleSp)
     }
 }