# Flash going nuts when array.length given for iteration limit of loop

**URL:** <https://forum.kirupa.com/t/flash-going-nuts-when-array-length-given-for-iteration-limit-of-loop/212605>\
**Category:** Uncategorized\
**Created:** [January 12, 2007, 1:56pm UTC](https://forum.kirupa.com/t/flash-going-nuts-when-array-length-given-for-iteration-limit-of-loop/212605 "2007-01-12T13:56:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pup\_100](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@Pup\_100](https://forum.kirupa.com/u/Pup_100)\
**Post date:** [January 12, 2007, 1:56pm UTC](https://forum.kirupa.com/t/flash-going-nuts-when-array-length-given-for-iteration-limit-of-loop/212605/1 "2007-01-12T13:56:26Z")

</div>

The following script, which has been adapted from a grid generation script, does just what it says on the tin – traces “p” out 352 times;

[AS]for (var i = 1; i\<=16; ++i) {  
for (var p = 1; p\<=22; ++p) {  
var x = (p-1)\*spacing;  
var y = (i-1)\*spacing;  
var name = “cell”+p+"\_"+i;  
hold\_array.push(name);  
this.holdit\_mc.nhold\_mc.attachMovie(“little”, name, ++depth);  
this.holdit\_mc.nhold\_mc[name].\_x = x;  
this.holdit\_mc.nhold\_mc[name].\_y = y;  
}  
}

for (p=0; p\<=352; p++) {  
trace§;  
}[/AS]

But… if I change the loop to the following;

[AS]for (p=0; p\<=hold\_array.length; p++) {  
trace§;  
}[/AS]

all hell breaks loose & Flash advises me to dump the script?

Is it that the “loop” is being called BEFORE hold\_array has had a chance to be populated?

Many thanks for any help.
