# Creating new Bad Guys

**URL:** https://forum.kirupa.com/t/creating-new-bad-guys/331242
**Category:** flash
**Created:** [June 19, 2013, 11:51am UTC](https://forum.kirupa.com/t/creating-new-bad-guys/331242 "2013-06-19T11:51:46Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Joao\_Andrade](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@Joao\_Andrade](https://forum.kirupa.com/u/Joao_Andrade)
#### Post date: [June 19, 2013, 11:51am UTC](https://forum.kirupa.com/t/creating-new-bad-guys/331242/1 "2013-06-19T11:51:46Z")

</div>

So, i have a problem here…  
I want to creat every “x” tyme a bad guy in my game and when it collide with the player, i lose a life. Simple…  
But whenever it creats a new bad guy, the previous ones lose their instance name or something and i dont lose a life because it doesnt not recognise the “bad guy” instance…  
What i have to do? I want that all the bad guys in the field can make the player lose a life.  
I’m using this code to create the new bad guy:

```auto
contadorTempo.addEventListener(TimerEvent.TIMER, intervaloTempo2);//evento para nascimento do mau da direta  
function intervaloTempo2(evento:TimerEvent):void {  
    mau=new Black_Player ();   
    addChild (mau);   
    mau.rotation = 180; //rotação do mau   
    mau.x = 1024; //posição de x do mau é igual a 0    
    mau.y = Math.random()*540; //posição y do mau é feita aleatóriamente entre os valores 1 e 540 de y    
   mau.addEventListener(Event.ENTER_FRAME, movermau2);//quando nasce o novo mau, esta função faz-lo mover-se da direita  
} 

```

And, for the collision with the player, im using this code:

```auto
stage.addEventListener(Event.ENTER_FRAME, perdervida);  
function perdervida(evento:Event):void {      
      if( jogador_bom.hitTestObject(mau) == true )
      {     
          vida = vida - 1;     
          mau.x = 10000;      
           trace("AUCH");      
          livetext.text = String(vida); // código para aparecer o número de vidas do jogador no ecra
 }  
} //função para perder uma vida

```

PS: sorry about the english, not my language, and i hope u understand my question, and i hope this insert code is good like the others question. I spent like 20 minutes just to figure this out. First time here.  
Cheers 🙂
