Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Aug 04, 2016 Aug 04, 2016

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;
  
}
}

TOPICS
ActionScript
305
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2016 Aug 04, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 04, 2016 Aug 04, 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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 05, 2016 Aug 05, 2016
LATEST

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines