views:

1800

answers:

1

I have 5 movieclips called row1, row2, ..., row5. Inside each row are the movieclips let1, let2, ..., let15. I want to assign all of the letter clips to a 2 dimensional array. This is a followup to an earlier question http://stackoverflow.com/questions/538133/dynamically-accessing-nested-movie-clips-in-flash-actionscript-2 .

I am trying this:

var letterClips:Array = [];

for( var i = 1; i <= 5; i++) {

letterClips[i] = new Array(16);

//var row:MovieClip = _root["row" + i];
//rowClips.push(row);

for ( var j = 1; j <= 15; j++) {

 var letter:MovieClip = _root["row" + i]["let" + j];

 letterClips[i].push(letter);

}

}

+2  A: 

Well, if you use

letterClips[i].push(letter);

That's going to add 'letter' to the end of the array and increase its size (by 1). So it will start adding 'letter' movies at position 16, and continue with 17, 18,...

Solution 1: replace

letterClips[i] = new Array(16);

with

letterClips[i] = new Array();

Solution 2: replace

letterClips[i].push(letter);

with

letterClips[i][j] = letter;

Either one should work.

P.S. Also note that since your indices (i,j) start at 1, your [0][j] and [i][0] slots will be undefined by the time you go through all the iterations.

euge1979