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

flash on 2009-7-15

Get Adobe Flash player
by mtarbit 15 Jul 2009
/**
 * Copyright mtarbit ( http://wonderfl.net/user/mtarbit )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/3oyP
 */

package {

	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.events.Event;
	import flash.events.MouseEvent;

	[SWF(backgroundColor=0x000000, frameRate=24)]
	
	public class Main extends Sprite {
		public var mouseIsDown:Boolean = false;

		public var maxCircles:int = 200;
		public var circles:MovieClip = new MovieClip();
		
		public function Main() {
			var format:TextFormat = new TextFormat();
			format.bold = true;
			format.size = 24;
			format.align = 'center';
			format.font = "Helvetica";
                        format.color = 0xFFFFFF;

			var field:TextField = new TextField();
			field.width = stage.stageWidth;
			field.text = "Click & Drag";
			field.setTextFormat(format);

			field.x = (stage.stageWidth - field.width) / 2;
			field.y = (stage.stageHeight - field.height) / 2;

			addChild(field);
			addChild(circles);

			stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
			stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
			stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
			stage.addEventListener(Event.ENTER_FRAME, onLoop);
                }

		public function newCircle(x:int, y:int):void {
			var color:uint = (Math.random() * 0xffffff);
			var radius:uint = 5 + Math.round(45 * Math.random());
			var circle:MovieClip = new MovieClip();

			circle.x = x;
			circle.y = y;

			circle.graphics.beginFill(color, 1);
			circle.graphics.drawCircle(0, 0, radius);

			circles.addChild(circle);
		}

		public function moveCircle(circle:DisplayObject, n:int):void {
			circle.alpha = 1 - (n / maxCircles);
			if (circle.alpha <= 0) {
				circles.removeChild(circle);
			}
			if (circle.y < stage.stageHeight) {
				circle.y += 10;
			}
		}

		public function onDown(event:MouseEvent):void {
			mouseIsDown = true;
		}
		public function onMove(event:MouseEvent):void {
			if (mouseIsDown) newCircle(mouseX, mouseY);
		}
		public function onUp(event:MouseEvent):void {
			mouseIsDown = false;
		}

		public function onLoop(event:Event):void {
			var n:int = circles.numChildren;
			for (var i:int = (n-1); i>=0; i--) {
				moveCircle(circles.getChildAt(i), n-i);
			}
		}

	}

}