Skip to main content
Known Participant
August 4, 2016
Question

Call the same object from library each one has it own properties.

  • August 4, 2016
  • 3 replies
  • 329 views

I have some enemies(let say 10 enemies) on stage with the same instance names "enemy".

Each enemy have 4 hitpoints.

When a bullet hit a enemy the enemy remove from stage and a new enemy (enemy2) spawn on stage.

How can i do the spawn enemy to have let say 4 hitpoints?

Here is what i do for the enemies on stage to have 4 hitpoints.

var enemyArray:Array = new Array();
for (var e:int = numChildren - 1; e>= 0; e--)
{
  
var childe:DisplayObject = getChildAt(e);
  
if (childe.name == "enemy")
  
{
      enemyArray
.push(MovieClip(childe));
     
MovieClip(childe).hitpoints = 4;
  
}
}

This topic has been closed for replies.

3 replies

Known Participant
August 5, 2016

I think i found what i must to do.

I just put hitpoints the time i create the new enemies .

var enemy1:Enemy = new Enemy;

  enemy1Array.push(enemy1);

  this.addChild(enemy1);

  enemy1.hitpoints = 3;

Known Participant
August 4, 2016

This is for enemies that are already on stage with instance name .This enemies have this property(4 hitpoints)..

When i shot the enemy , a new enemy spawn.

That i am trying to do is, the new enemy to have they own properties(3 hitpoints).

kglad
Community Expert
Community Expert
August 4, 2016

1. they shouldn't have the same name.

2. assign whatever properties (like hitpoints) that you want (which you do in your last line of shown code).

3. because your code doesn't make sense, what are you trying to do?  ie, do you want to have different enemies with different hitpoints?