Array problem, can you spot a flaw?

• 03-28-2010, 10:51 PM
SirN
SOLVED Array problem, can you spot a flaw?
Hi,

I have a problem with an function in my movie, I want to pick from an array but I need to choose the array dynamically. index [0] from my35Array or my1Array - I don't get it to work, can you spot an flaw or suggest something that works?

Code:

```                                my35Array = ["1.0"]; // vildhet 35 my1Array = ["4.9","4","3.7","3.5","2.8","2.2","0.3","0.2","0.16","0.12"]; // vildhet 1 trace (dragg); function vildhetsdragg(vildhet,fas4)         {                 toNumber (vildhet);                 toNumber (fas4);                                                 arrayfighter = vildhet;                 // trace (arrayfighter);                 bonusfighter =  "my" + arrayfighter + "Array";                 extrafighter = bonusfighter;                 // toString (bonusfighter);                 trace (extrafighter);                 trace (fas4);                                 if (fas4 > 89)                         {                                 // trace (extrafighter[0]);                                 trace (my35Array[0]);                                 dragg = extrafighter[0];                                                                                                                 }                                         }```
bonusfighter and extrafighter becomes myXArray as it should (in this case 1 or 35 is the only Arrays created), but dragg = extrafighter[0]; does not pick e.g. my35Array[0] even if extrafighter is my35Array !

dragg = extrafighter[0] is always 109 for some reason I cannot understand!

Can you spot a flaw or tell me how to pick from the array with an dynamic way?
• 03-29-2010, 06:03 PM
SirN
I've found an solution! Hurray!

I need to do 99 diffferent copy proccesses between 2 Arrays of it:

if (vildhet == 1) // 1-99 needs the same treatment
{
bonusfighterArray[0] = my1Array[0];
// there will perhaps be as many as 30
// Array indexes, but not more...
}

if (fas4 > 89) // there will perhaps be as many as 30 conditions here
{
dragg = bonusfighterArray[0];
}

This does the job, but I would perhaps be better of if there is a way to copy an array (all the contents of it without haveing to spell it out like I here show that I am about to do), is there a way to completely copy all of an Array to another?
• 03-29-2010, 06:39 PM
dawsonk
Code:

`extrafighter = extrafighter.concat(this["my"+arrayfighter+"Array"]);`