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 undo 24 Jul 2009
/**
 * Copyright undo ( http://wonderfl.net/user/undo )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6i5p
 */



package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	public class FlashTest extends Sprite
	{
		private var array:Array = new Array();
		private var grv:Number = 1;
		private var bounce:Number = 0.5;
		private var limitSpeed:Number = 1;
		private var minRadius:Number = 5;
		private var maxNum:int = 100;
		public function FlashTest()
		{
			init();
		}
		private function init():void
		{
			// write as3 code here..
			makeFirstBall();
			addEventListener(Event.ENTER_FRAME, onEnter);
		}
		private function makeFirstBall():void
		{
			var b:Ball = new Ball(50,Math.random()*10-5,0);
			b.x = stage.stageWidth/2;
			b.y = stage.stageHeight/2;
			addChild(b);
			array.push(b);
		}
		private function onEnter(evt:Event):void
		{
			var l:int = array.length;
			for (var i:int = l - 1; i >= 0; i--)
			{
				var b:Ball = array[i];
				var bounded:Boolean = false;
				b.vy += grv;
				b.x += b.vx;
				b.y += b.vy;
				if (b.x+b.r > stage.stageWidth || b.x-b.r < 0)
				{
					b.x -= b.vx;
					b.vx = -b.vx * bounce;
					b.vy = b.vy * bounce;
					bounded = true;
				}
				if (b.y+b.r > stage.stageHeight || b.y-b.r < 0)
				{
					b.y -= b.vy;
					b.vx = b.vx * bounce;
					b.vy = -b.vy * bounce;
					bounded = true;
				}
				if (bounded && Math.sqrt(b.vx*b.vx + b.vy*b.vy) < limitSpeed)
				{
					array.splice(i,1);
					if (b.r > minRadius)
					{
						for (var j:int = 0; j < 4; j++)
						{
							var b1:Ball = new Ball(b.r*0.7, Math.random()*100-50, Math.random()*100);
							b1.x = b.x;
							b1.y = b.y;
							addChild(b1);
							array.push(b1);
						}
					}
					else if(array.length == 0)
					{
                                            makeFirstBall();
					}
					removeChild(b);
					b = null;
				}
			}
		}
 	}
 }
 
 import flash.display.Sprite;
 	class Ball extends Sprite
	{
		public var r:Number;
		public var vx:Number;
		public var vy:Number;
		
		public function Ball(rad:Number = 100, vx:Number = 0, vy:Number = 0)
		{
			r = rad;
			this.graphics.beginFill(0xff0000);
			this.graphics.drawCircle(0,0,r);
			this.graphics.endFill();
			
			this.vx=vx;
			this.vy=vy;
		}
	}