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 Evolutor 25 Jan 2010
/**
 * Copyright Evolutor ( http://wonderfl.net/user/Evolutor )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ecIN
 */

package{
	import flash.display.*;
	import flash.events.*;

	public class Main extends Sprite{
		public function Main(){
			stage.frameRate = 60;
			var gravity:Number = 0.5;
			var ballY:int = -22;
			for (var i:int=0; i<50; i++){
				var ball:MovieClip = new MovieClip();
				ball.graphics.beginFill(0xffffff*Math.random());
				ball.graphics.drawCircle(0, 0, 10);
				ball.graphics.endFill();
				ball.speedX = Math.random()*10-5;
				ball.speedY = Math.random()*ballY;
				addChild(ball);
				ball.addEventListener(Event.ENTER_FRAME, randomBall);
			}
			
			function randomBall(evt:Event):void{
				var ball:MovieClip = MovieClip(evt.target);
				ball.speedY += gravity;
				ball.x += ball.speedX;
				ball.y += ball.speedY;
				if (ball.y>stage.stageHeight){
					ball.speedX = Math.random()*10-5;
					ball.speedY = Math.random()*ballY;
				}
				// ballが右側の壁に当たった時の処理
				if(ball.x>stage.stageWidth-10){
					ball.speedX *= -1;
				}
				// ballが左側の壁に当たった時の処理
				if(ball.x<0){
					ball.speedX *= -1;
				}
			}
		}
	}
}