You alter the only variable, named damage
, and then you assign that damage to each of the enemies in turn, that's why you do the same damage to all the enemies. Instead, you should apply the damage to one enemy at a time within that loop of yours.
var j:int;
for (j = 0; j < enemyArray.length; j++)
{
if (enemyArray[j] != null)
{
trace(enemyArray[0].enemyElement, enemyArray[1].enemyElement)
if (player.playerElement == "Electric")
{
if (enemyArray[j].enemyElement == "Water")
{
//DO A LOT OF DAMAGE
damage = 20
}
else if (enemyArray[j].enemyElement == "Fire")
{
//DONT DO A LOT OF DAMAGE
damage = 10
}
}
// put all the other elements of player&enemy in here
enemyArray[j].takeDamage(damage);
// and then apply the calculated damage to only j'th enemy, not to every enemy
}
}