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

ActionScript練習 ボールをいっぱい書いてみる

Get Adobe Flash player
by pon_zu 04 Feb 2010
/**
 * Copyright pon_zu ( http://wonderfl.net/user/pon_zu )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/h4m2
 */

package 
{
	import flash.display.*;
	import flash.events.Event;
	
	public class Main extends Sprite 
	{
		public function Main():void 
		{
			for (var i:uint = 0; i < 100; i++){
				var myCircle:Circle = new Circle();				
				myCircle.x = 0;
				myCircle.y = 0;
				addChild(myCircle); //表示リストに追加
			}
		}		
	}
}

		import flash.display.Sprite;
        import flash.events.Event;
		import flash.events.MouseEvent;

        class Circle extends Sprite {
                public function Circle()
                {
					x = Math.random() * 800;
					y = Math.random() * 600;				
					_speedX = rand(-18,18);
					_speedY = rand(-18,18);

					var sp:Sprite = new Sprite();
					sp.graphics.beginFill(Math.random() * 0xFFFFFF);					
					sp.graphics.drawCircle(0, 0, rand(20, 60));
					sp.alpha = 0.2;
					addChild(sp);
					addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
                }
				
				private var _speedX:Number;
                private var _speedY:Number;

                private function onEnterFrameHandler(event:Event):void
                {
                        limit();
                        x += _speedX;
                        y += _speedY;
                }
				
				private function limit():void
                {
                        if(x < 0 || x > 800){
                                _speedX *= -1;
                        }
                        if(y < 0 || y > 600){
                                _speedY *= -1;
                        }
                }
				
				private function rand(min:Number, max:Number):Number
                {
					var randValue:Number = Math.random() * (max - min) + min;
					return randValue;
                }

        }