# Loop and onEnterFrame

**URL:** <https://forum.kirupa.com/t/loop-and-onenterframe/191647>\
**Category:** Uncategorized\
**Created:** [June 22, 2006, 1:36am UTC](https://forum.kirupa.com/t/loop-and-onenterframe/191647 "2006-06-22T01:36:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![OMG](https://avatars.discourse-cdn.com/v4/letter/o/9dc877/32.png) [@OMG](https://forum.kirupa.com/u/OMG)\
**Post date:** [June 22, 2006, 1:36am UTC](https://forum.kirupa.com/t/loop-and-onenterframe/191647/1 "2006-06-22T01:36:12Z")

</div>

hi, I’m trying to make a game, there’s lots of enemies and one player, here’s the problem:  
when the player hits an enemy, I need to check which enemy it is. So I was thinking to use a loop that loop through all the enemy MC(enemy\_0, enemy\_1, enemy\_2,enemy\_3…):

```auto
 
var enemyNumber:Number = 50
for(var i:Number=0; i<=enemyNumber; i++){
    if(this.hitTest(_root["enemy"+i])){
        //code here......
    }
}

```

but later I thought this isn’t very effective, so I decided to put this ON EACH ENEMY:

```auto
 
this.onEnterFrame=function(){
    if(_root.playerClip.hitTest(this)){
        //code here......
    }
}

```

can you tell me which one is better?  
thanks a lot
