Groups | Blog | Home
all groups > flash actionscript > november 2005 >

flash actionscript : ARRAY SYNTAX


NSurveyor
11/23/2005 7:51:28 PM
Kglad...[b] _root["p"+p][j-1][/b] !!!

[quoted text, click to view]

jonnybennett
11/23/2005 11:49:54 PM
Basically I have data in 5 arrays called TTArray1 - TTArray5. I want to take
the first piece of data from each of these arrays and it into a new array. I
then want to take the second piece of data from each of these arrays and place
that into antoher new array and so on, untill I have extracted all the data
from my original TTArray1 - TTArray5. i.e. I am changing the order of the
arrays.

//please note there are 10 pieces of data in each of the arrays.

for (p=0;p<10;p++){
id.p = new Array();
id.p[0]= TTArray1[p];
id.p[1]= TTArray2[p];
id.p[2]= TTArray3[p];}

but this does not work... I think it is because I'm getting confused with
the'.' I thought that consentened but maybe that is only strngs and in php???
If anyone knows what i am onabout or can help that would be ace.. thanks JOnnie.


kglad
11/24/2005 12:00:00 AM
which code do you want explained? surveyor created one 2-dimensional array to
contain all your array elements and i created 10 1-dimensional arrays to
contain all your array elements.

beyond that (noting surveyor's correction of my code), there isn't any
significant difference.
NSurveyor
11/24/2005 12:00:00 AM
No problem

Okay... here's what I did with my code..

First I made an array, id to hold the final array.
id = [ ];
//we loop through p from 0 to 9 for each of the elements in the arrays
for(var p=0;p<10;p++){
//now we have an array to hold all the "p"th values of your arrays
//For example, for the first time this code loops, we will have
//id[0] = [ ], which will be the array we hold all the first elements of
//the TTarrays
id[p] = [ ];
//We loop t from 1 to 5 for each array
for(var t=1;t<=5;t++){
//Because you started at TTArray1 and arrays are 0 based,
//the First element in id[p] is id[p][0] which we set to this["TTArray"+t][ p ]
id[p][t-1] = this["TTArray"+t][p];
}
}

Sorry I'm pretty vague, because I have to go somewhere... hopefully Kglad will
explain better.
NSurveyor
11/24/2005 12:41:10 AM
I think this should do the trick:

id = [ ];
for(var p=0;p<10;p++){
id[p] = [ ];
for(var t=1;t<=5;t++){
id[p][t-1] = this["TTArray"+t][p];
}
kglad
11/24/2005 12:46:55 AM
for (var p = 0; p<10; p++) {
_root["p"+p] = [];
for (var j = 1; j<=5; j++) {
_root["p"+p][j] = _root["TTArray"+j][p];
}
AddThis Social Bookmark Button