package com.sarmatianHeroes.objects 
{
	import flash.display.*;
	import flash.events.*;
	
	import com.antkarlov.math.*;
	
	public class Lightning extends MovieClip
	{
		private var _vis:MovieClip;
	
		public function Lightning(sq:Object)
		{
			if(Math.random()>0.5)
			{
				_vis = new Lightning_01;
			}
			else
			{
				_vis = new Lightning_02;
			}
			
			_vis.x = sq.x + Amath.random(-40,40);
			_vis.y = sq.y - Amath.random(-10,10)-_vis.height/5;
			_vis.scaleX = _vis.scaleY = 0.2;
			_vis.rotation += Amath.random(-40,40);
			_vis.gotoAndStop(1);
			addChild(_vis);
			//stage.addChild(this);
			addEventListener( Event.ENTER_FRAME, fly );
		}
	
		
		private function fly( e:Event ):void
		{
			_vis.nextFrame();
			if(_vis.currentFrame == _vis.totalFrames)
			{
				_vis.stop();
				parent.removeChild(this);
				removeEventListener( Event.ENTER_FRAME, fly );
			}
		}
	}
}
