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

sonar

click
Get Adobe Flash player
by Scmiz 30 Apr 2011
    Embed
/**
 * Copyright Scmiz ( http://wonderfl.net/user/Scmiz )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mdNG
 */

package {
    import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	
    public class FlashTest extends Sprite {
		private var _ringArray:Array = new Array();
		private var _bitArray:Array = new Array();
		
        public function FlashTest() {
			this.graphics.beginFill(0x000000);
			this.graphics.drawRect(0, 0, 465, 465);
			this.graphics.endFill();
			
			for (var index:uint = 0; index < 80; ++index) {
				var bit:Bit = new Bit();
				bit.x = Math.random() * 465;
				bit.y = Math.random() * 465;
				this.addChild(bit);
				_bitArray.push(bit);
			}
			
			stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
			stage.addEventListener(Event.ENTER_FRAME, proc);
        }
		
		private function proc(e:Event):void {
			for (var index:uint = 0; index < _ringArray.length; ++index) {
				// 消去
				if (_ringArray[index].isEnd) {
					this.removeChild(_ringArray[index]);
					_ringArray.splice(index, 1)
					--index;
					continue;
				}
				
				// 当たり判定
				{
					var prev:Number = _ringArray[index].radiusPrev;
					var current:Number = _ringArray[index].radius;
					var pos:Point = new Point(_ringArray[index].x, _ringArray[index].y);
					
					for each (var bit:Bit in _bitArray) {
						var rhsPos:Point = new Point(bit.x, bit.y);
						var dist:Number = (new Point(pos.x - rhsPos.x, pos.y - rhsPos.y)).length;
						
						if (prev < dist && current >= dist) {
							bit.detected();
						}
					}
				}
				
				// 前回位置
				_ringArray[index].updatePrev();
			}
		}
		
		private function onDown(e:MouseEvent):void {
            var r:Ring = new Ring();
			r.x = stage.mouseX;
			r.y = stage.mouseY;
			this.addChild(r);
			_ringArray.push(r);
		}
    }
}
import flash.display.Sprite;
import caurina.transitions.Tweener;
import flash.events.Event;

class Ring extends Sprite
{
	private var _radius:Number;
	private var _radiusPrev:Number;
	private var _isEnd:Boolean;
	
	public function set radius(value:Number):void { _radius = value; }
	public function get radius():Number { return _radius; }
	public function get radiusPrev():Number { return _radiusPrev; }
	public function get isEnd():Boolean { return _isEnd; }
	
	public function Ring() {
		_radius = 2.0;
		_radiusPrev = _radius;
		_isEnd = false;

		var onUpdate:Function = function():void {
			this.graphics.clear();
			this.graphics.lineStyle(3, 0x0000ff);
			this.graphics.drawCircle(0, 0, _radius);
		}
		var onComplete:Function = function():void {
			_isEnd = true;
		}
		Tweener.addTween(this, { radius:200, alpha:0.5, time:50, useFrames:true, transition:"linear", onUpdate:onUpdate, onComplete:onComplete } );
	}
	
	public function updatePrev():void {
		_radiusPrev = _radius;
	}
}

class Bit extends Sprite
{
	private var _flag:Boolean = Math.random() < 0.5;
	
	public function Bit() {
		var size:Number = 4.0;
		var round:Number = 2.0;
		this.graphics.beginFill(0x0000ff);
		this.graphics.drawRoundRect(-size * 0.5, -size * 0.5, size, size, round, round);
		this.graphics.endFill();
		this.alpha = 0;
		
		switch (uint(Math.random() * 4)) {
			case 0:
				this.addEventListener(Event.ENTER_FRAME, updateHorizontal);
				break;
			case 1:
				this.addEventListener(Event.ENTER_FRAME, updateVertical);
				break;
		}
	}
	
	private function updateHorizontal(e:Event):void {
		this.x += 2.0 * (_flag ? 1 : -1);
		if (this.x < 0) {
			this.x = 0;
			_flag = true;
		}
		if (this.x > 465) {
			this.x = 465;
			_flag = false;
		}
	}

	private function updateVertical(e:Event):void {
		this.y += 2.0 * (_flag ? 1 : -1);
		if (this.y < 0) {
			this.y = 0;
			_flag = true;
		}
		if (this.y > 465) {
			this.y = 465;
			_flag = false;
		}
	}
	
	public function detected():void {
		var frame:uint = 10;
		var frame2:uint = 20;
		Tweener.addTween(this, { alpha:1, time:frame, useFrames:true });
		Tweener.addTween(this, { alpha:0, delay:frame, time:frame2, useFrames:true } );
	}
}