A Flash Developer Resource Site

# Thread: Quest: arrays in for-loops

1. ## Quest: arrays in for-loops

I got a problem with enhanceing my code in FlashMX:
code:
```for (i=0; i<3; i++) {
P001[i+3] = P001[i];
}
for (i=0; i<3; i++) {
P002[i+3] = P002[i];
}
for (i=0; i<3; i++) {
P003[i+3] = P003[i];
} ```

This code makes copies of P00x[0,1,2] and places those copies in P00x[3,4,5]. Since I will have to go up to about P030 and maybe even higher later I wanted to add another for-loop like this:

code:
```for (i=1; i<PMax+1; i++) {
for (j=0; j<3; j++) {
P00i[j+3] = P00i[j];
}
}
```

The part marked bold is not valid code of course since I mustn't add the "i" right into the variable-name, but thats exactly the point where I dont know how write the code.
How can I make that line work, or in another way: how can I make that line dependant on the i-counter and still tell Flash, that "P00" and the counter-i toghether form the name of the variable?

2. One way to do it would be to create a multi-dimensional array, rather than having 30 discrete arrays.

code:
```
P00 = new Array(PMAX);
for (i=0; i<PMAX; i++) {
P00[i] = new Array(6);
}

...

for (i=0; i<PMax; i++) {
for (j=0; j<3; j++) {
P00[i][j+3] = P00[i][j];
}
}
```

3. Another way to do it - in your existing code - would be like this:
code:
```
for (i=1; i<PMax+1; i++) {
for (j=0; j<3; j++) {
this["P00"+i][j+3] = this["P00"+i][j];
}
}
```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap