Okay so this has been bugging me all day so I thought I would post it here. This is such a specific topic that it was basically impossible to find any sort of references on how this would be done.

```
for (var i:int=0; i<=Main.bloonList.length-1; i++)
{
    //loop through the children in enemyHolder
    var cEnemy = Main.bloonList[i];//define a movieclip that will hold the current child
    //this simple formula with get us the distance of the current enemy
    if (Math.sqrt(Math.pow(cEnemy.y - this.y,2) + Math.pow(cEnemy.x - this.x,2)) < 100)
    {
        shoot(cEnemy);
        timer = 0;
    }
}

```

This is the code i have at the moment and i would like to know how to figure out which enemy is the farest along the track. I can find it by using this.

```
function onEnter(e:Event)
{
    distanceTravelled=distanceTravelled+xSpeed+Yspeed
}

```

But how can I tell the for loop to target the one with the highest value?