# Help with arrays

**URL:** <https://forum.kirupa.com/t/help-with-arrays/185854>\
**Category:** Uncategorized\
**Created:** [April 17, 2006, 4:07am UTC](https://forum.kirupa.com/t/help-with-arrays/185854 "2006-04-17T04:07:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![handless](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@handless](https://forum.kirupa.com/u/handless)\
**Post date:** [April 17, 2006, 4:07am UTC](https://forum.kirupa.com/t/help-with-arrays/185854/1 "2006-04-17T04:07:56Z")

</div>

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.

```auto
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']
}

```

---

<div class="post-metadata">

**Author:** ![Dauntless](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/dauntless/32/749_2.png) [@Dauntless](https://forum.kirupa.com/u/Dauntless)\
**Post date:** [April 17, 2006, 9:14am UTC](https://forum.kirupa.com/t/help-with-arrays/185854/2 "2006-04-17T09:14:40Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 17, 2006, 9:30am UTC](https://forum.kirupa.com/t/help-with-arrays/185854/3 "2006-04-17T09:30:14Z")

</div>

> [@Dauntless](#):
>
> 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:

---

<div class="post-metadata">

**Author:** ![handless](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@handless](https://forum.kirupa.com/u/handless)\
**Post date:** [April 17, 2006, 1:27pm UTC](https://forum.kirupa.com/t/help-with-arrays/185854/4 "2006-04-17T13:27:00Z")

</div>

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](http://www.fuzzy-media.net/depthtest.fla)
