package com.sarmatianHeroes.objects 
{
	import flash.display.*;
	import flash.events.*;
	
	import com.antkarlov.math.*;
	
	public class DeadHeroBody extends MovieClip
	{
		private var _animNumber:int;
		private var _firstLayer:Object;
		private var _lastLayer:Object;
		private var _vis:MovieClip;
	
		public function DeadHeroBody(first:Object,last:Object,hero:HeroBase)
		{
			_firstLayer = first;
			_lastLayer = last;
			_animNumber = 1 + Math.floor(Math.random()*2);
			if(hero is HeroBow)
			{
				_vis = new HeroBow_death_mc;
			}
			else if(hero is HeroClub)
			{
				_vis = new HeroClub_death_mc;
			}
			else if(hero is HeroMag)
			{
				_vis = new HeroMag_death_mc;
			}
			else if(hero is HeroSword)
			{
				_vis = new HeroSword_death_mc;
			}
			_vis.x = hero.x + Amath.random(-10,10);
			_vis.y = hero.y + Amath.random(-10,10);
			_vis.gotoAndStop("death_0"+_animNumber.toString());
			_firstLayer.addChild(_vis);
			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 );
			}
		}
	}
}
