79760463

Date: 2025-09-10 04:25:51
Score: 0.5
Natty:
Report link

Ok. I found solution in different question. This is whole code. To the code that i added I wrote code explanation via "//". Basicly what happenes is that i create Listener for Every Enemy on the stage. If i click on the Enemy i can see the index of that Enemy in Array (i test it for my self with trace) and then apply all these actions for enemy that was clicked....

Excuse my bad english. Anyway thanks for help. Hope u understand....


for (var j:int = enemyNaScene.length -1; j> -1; j--) {   
 // For every Enemy on the stage create Listener 
 // that indicates if it was CLICKED - than play actions
    enemyNaScene[j].addEventListener(MouseEvent.CLICK, enemyNapaden);      
}
      function enemyNapaden(event:MouseEvent):void{
var j:int = enemyNaScene.indexOf(event.target);    
 // If i click on Enemy -> j = index position of Enemy on the Stage in Array 
    trace(enemyNaScene.indexOf(event.target));  // Show the index with Trace
        enemiesHp[j]-=1;                  //Apply that index number ("j") for Enemy -                         
trace(enemiesHp[j])                      //that was clicked further down the line
    aTextFields[j].text = String(enemiesHp[j])
    aTextFields[j].setTextFormat(myTextFormat)
    
    if(enemiesHp[j]==0){
        aTextFields[j].visible=false;
        enemyNaScene[j].gotoAndPlay("enemydead")
        enemyNaScene[j].removeEventListener(MouseEvent.CLICK, enemyNapaden)
      }
      }
         
Reasons:
  • Blacklisted phrase (0.5): thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Vojtěch Pavlíček