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 hokori 05 May 2009
    Embed
package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class Sample03 extends Sprite
	{	
		private var m_x:Number;
		private var m_y:Number;
		private var m_start_x:Number;
		private var m_start_y:Number;
		private var m_end_x:Number;
		private var m_end_y:Number;
		
		private var m_disp:Sprite;
		private var m_draw:Sprite;
		
		private var m_color:int;
		
		public function Sample03() 
		{
			this.m_disp = new Sprite();
			this.addChild(m_disp);
			
			this.m_draw = new Sprite();
			this.addChild(m_draw);

			init();
			
			this.addEventListener(Event.ENTER_FRAME, draw);
		}
		
		private function init():void {
			
			this.m_color = Math.random() * 0x33FFFF;
			
			m_start_x = Math.random() * 500;
			m_start_y = Math.random() * 500;	
			m_end_x = Math.random() * 500;
			m_end_y = Math.random() * 500;
			
			m_x = m_start_x;
			m_y = m_start_y;
			
			this.m_draw.graphics.clear();
			this.m_disp.graphics.clear();
			
			while(m_disp.numChildren > 0){
				m_disp.removeChildAt(0);
			}
			
			this.nextLine(m_x, m_y);
		}
		
		private function draw(e:Event):void {
			
			var x:Number = m_x + (m_end_x - m_start_x) * 0.05;
			var y:Number = m_y + (m_end_y - m_start_y) * 0.05;

			if ((m_end_x >= m_start_x && x >= m_end_x) || (m_end_x <= m_start_x && x <= m_end_x)) {
				x = m_end_x;
			}
			if ((m_end_y >= m_start_y && y >= m_end_y) || (m_end_y <= m_start_y && y <= m_end_y)) {
				y = m_end_y;
			}
			
			m_x = x;
			m_y = y;
			
			this.m_draw.graphics.moveTo(m_start_x, m_start_y);
			this.m_draw.graphics.lineTo(x, y);
			this.m_draw.graphics.drawCircle(m_end_x, m_end_y, 5);
			
			this.m_disp.graphics.clear();
			this.m_disp.graphics.lineStyle(0.5, this.m_color, 0.5);
		
			for (var i:int = 0; i < this.m_disp.numChildren; i++) {
			
				var child:Sprite = this.m_disp.getChildAt(i) as Sprite;
				if (i == 0) {
					this.m_disp.graphics.moveTo(child.x, child.y);
				}
				else{
					this.m_disp.graphics.lineTo(child.x, child.y);
				}
			}
			
			if (x == m_end_x && y == m_end_y) {
				
				this.nextLine(x, y);
				
				if (this.m_disp.numChildren > 30) {
					this.init();
					return;
				}
			}			
		}
		
		private function nextLine(x:Number, y:Number):void{
			
			m_x = x;
			m_y = y;
			m_start_x = x;
			m_start_y = y;			
			m_end_x = Math.random() * 500;
			m_end_y = Math.random() * 500;
			
			this.m_draw.graphics.clear();
			this.m_draw.graphics.lineStyle(1, this.m_color);

			var item:Sprite = new Sprite();
			item.graphics.beginFill(0x556677);
			item.graphics.drawCircle(0, 0, 5);
			item.graphics.endFill();
			
			var len_cnt:int = 1;
			var len_max:int = Math.random() * 30 + 10;
			
			var self:Sample03 = this;
			
			item.addEventListener(Event.ENTER_FRAME, 
								  function(e:Event):void {
									
									item.graphics.clear();
									item.graphics.lineStyle(0.5, self.m_color);
									
									for (var j:int = 0; j < len_max; j++){
										var angle:Number = (360 / len_max) * j / 180 * Math.PI;
										item.graphics.moveTo(0, 0);
										item.graphics.lineTo(Math.cos(angle) * len_cnt, Math.sin(angle) * len_cnt);
									}
									
									len_cnt += 2;
									
									if(len_cnt > len_max){
										item.removeEventListener(Event.ENTER_FRAME, arguments.callee);
										item.cacheAsBitmap = true;
									}
								  }, false, 0, true);
			
			item.x = x;
			item.y = y;
			
			this.m_disp.addChild(item);
		}
	}
}