Skip to main content
Inspiring
October 2, 2015
Answered

Get Index of Property That Holds An Object In An Array

  • October 2, 2015
  • 2 replies
  • 554 views

I have 3 arrays, structured so that one holds the frame label for the animation, and the other two hold the high and low values for the random damage calculator(which is working fine). There is a property called curAnim which gets set in a function to a random index in itself (a string, because it's a frame label). I need to be able to set a property that will hold the correct damage values to an index of the high and low damage arrays that is the same index of the frame label. Here is some code:

switch(curType)

  {

  case 'atk':

  curAnim = attackList[randomCalc(0, attackList.length)];

  if(curAnim == null)

  {

  gotoAndPlay('punch');

  curTarget.damage(atkDamL[curAnim], atkDamH[curAnim]); // here I try to send the high and low damage values to the enemy target (and the damage function works fine)

  returnMe();

  }

  else

  {

  gotoAndPlay(curAnim);

  curTarget.damage(atkDamL[curAnim], atkDamH[curAnim]);

  //returnMe();

  }

  break;

This topic has been closed for replies.
Correct answer Ned Murphy

To determine the index of something in an array you can use the indexOf method of the Array class.

theIndex = arrayName.indexOf("frame_label_text")

2 replies

Ned Murphy
Ned MurphyCorrect answer
Legend
October 3, 2015

To determine the index of something in an array you can use the indexOf method of the Array class.

theIndex = arrayName.indexOf("frame_label_text")

mcdermittAuthor
Inspiring
October 5, 2015

Thanks a lot! It works like a charm now.

Ned Murphy
Legend
October 5, 2015

You're welcome

kglad
Community Expert
Community Expert
October 3, 2015

i do not understand what you're trying to do.  maybe an example would help.