Help with arrays

Can anyone tell why this doesnt work. like when i click the button that calls getdepth the first two buttons work, the first time you click them but then nothing else work at all. after the first two buttons i just get undefined. any help would be awesome.

stop();
var depths:Array = new Array();
depths['1'] = 'b1';
depths['2'] = 'b2';
depths['3'] = 'b3';
depths['4'] = 'b4';
depths['5'] = 'b5';

function getdepth(mc){
 if (depths['1'] == mc) {}
 if (depths['2'] == mc) {reorder(mc,2);}
 if (depths['3'] == mc) {reorder(mc,3);}
 if (depths['4'] == mc) {reorder(mc,4);}
 if (depths['5'] == mc) {reorder(mc,5);}
}

function reorder(mc,currpos){
    var i = 2;
    var b = 1;
    var depthtemp:Array = new Array();
    depthtemp['1'] = mc;
do { depthtemp* = depths**;
i++;
b++;
} while (i<currpos+1);
     var t = 1;
do { depths[t] = depthtemp[t];
t++;
} while (t<6);
t1.text = depths['1']
t2.text = depths['2']
t3.text = depths['3']
t4.text = depths['4']
t5.text = depths['5']
}

Why do you use an associative array? (And not just depths[0], depths[1], depths[2]).

And in the reorder function, you don’t use an associative array…

And last: that while loop doesn’t make any sense…

Instances of the Array class are associative arrays which simply use numbers instead of letters: depths[0]; is the same as depths[“0”];

There is also nothing wrong with the while loops either from what I can tell with what little information he has given.

Now for your problem, you should first that arrays are 0-based meaning that 0 is the first index - not 1. Change this and you will avoid a lot of confusion. Other than that the code looks fine so you’ll need to post the rest and a better description of how everything is set up, or preferably an FLA.

:hoser:

hey sorry bout the lack of information. im attaching a fla. in the fla there are boxes, they will fall down and become windows but i want them to be draggable and when you click them they should come to the front but i want them to stay in order as far as what order they were in. if that makes sense, in a different flas i have the boxes set up to drop and become windows, and i have the draggable function in there. i just need to figure out the depth deal and then im good. anyways any help would be awesome.

fla