package com.sarmatianHeroes.objects 
{
	import flash.display.*;
	import flash.events.*;
	
	import com.antkarlov.math.*;
	import com.greensock.*; 
	import com.greensock.easing.*;
	import com.greensock.plugins.*;
	
	public class DeadBody extends MovieClip
	{
		private var _animNumber:int;
		private var _firstLayer:Object;
		private var _lastLayer:Object;
		private var _vis:MovieClip;
	
		public function DeadBody(first:Object,last:Object,sq:Squad)
		{
			_firstLayer = first;
			_lastLayer = last;
			_animNumber = 1 + Math.floor(Math.random()*6);
			switch(sq._visType)
			{
				case "HazarSword": _vis = new HazarSword_death_mc; _vis.scaleX = _vis.scaleY = 0.5; break;
				case "HazarBow": _vis = new HazarBow_death_mc; _vis.scaleX = _vis.scaleY = 0.5; break;
				case "HazarSpear": _vis = new HazarSpear_death_mc; _vis.scaleX = _vis.scaleY = 0.6; break;
			}
			_vis.x = sq.x + Amath.random(-30,30);
			_vis.y = sq.y + Amath.random(-30,30);
			_vis.gotoAndStop("death_0"+_animNumber.toString());
			_firstLayer.addChild(_vis);
			TweenPlugin.activate([TintPlugin]);
			TweenLite.to(_vis, 6, {tint:0x222222});
		
			addEventListener( Event.ENTER_FRAME, fly );
		}
	
		
		private function fly( e:Event ):void
		{
			_vis.nextFrame();
			if(_vis.currentFrameLabel == "death_0"+_animNumber.toString()+"_end")
			{
				_vis.stop();
				_firstLayer.removeChild(_vis);
				_lastLayer.addChild(_vis);
				removeEventListener( Event.ENTER_FRAME, fly );
			}
		}
	}
}
