# Help with for loops and variables

**URL:** https://forum.kirupa.com/t/help-with-for-loops-and-variables/267662
**Category:** flash
**Created:** [August 4, 2008, 4:15pm UTC](https://forum.kirupa.com/t/help-with-for-loops-and-variables/267662 "2008-08-04T16:15:49Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![bobcahill](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@bobcahill](https://forum.kirupa.com/u/bobcahill)
#### Post date: [August 4, 2008, 4:15pm UTC](https://forum.kirupa.com/t/help-with-for-loops-and-variables/267662/1 "2008-08-04T16:15:49Z")

</div>

I need to have a Flash program I am creating loop through creation of 10 instances that each get populated by different dynamic XML files. Everything works fine, but if I can get some help with my for loops pasted below my code will go from 900 lines of code to about 200. There are three commented lines that explain what I need done. One at the beginning and two before the functions. Thanks

//needs to be a for loop, but the syntax that works aFacilityDataID\* doesn’t seem to work when creating the variable.  
var aFacilityDataID1:Array = new Array();  
var aFacilityDataID2:Array = new Array();  
var aFacilityDataID3:Array = new Array();  
var aFacilityDataID4:Array = new Array();  
var aFacilityDataID5:Array = new Array();  
var aFacilityDataID6:Array = new Array();  
var aFacilityDataID7:Array = new Array();  
var aFacilityDataID8:Array = new Array();  
var aFacilityDataID9:Array = new Array();  
var aFacilityDataID10:Array = new Array();

//needs to loop through 10 instances of this function. Can you do that when making functions?  
//also in this for loop, this works, aFacilityXpos7[j], but trying to do this doesn’t (aFacilityYpos[arrayNumber][j]). Is there a way to have the two side by side work together?  
function sameSpace7(arrayNumber, nodesLength, currentX, currentY) {  
for(j:Number = 0; j \<= nodesLength -1; j++) {;  
if (((currentX-aFacilityXpos7[j])\<=11) && ((currentX-aFacilityXpos7[j])\>=-11)) {  
if (((currentY-aFacilityYpos7[j])\<=11) && ((currentY-aFacilityYpos7[j])\>=-11)) {  
if (arrayNumber != j) {  
\_root.container\_mc.firstload[“instance”+arrayNumber].\_y = (\_root.container\_mc.firstload[“instance”+j].\_y+15);  
}  
}  
}  
}  
}  
function sameSpace8(arrayNumber, nodesLength, currentX, currentY) {  
for(j:Number = 0; j \<= nodesLength -1; j++) {;  
if (((currentX-aFacilityXpos8[j])\<=11) && ((currentX-aFacilityXpos8[j])\>=-11)) {  
if (((currentY-aFacilityYpos8[j])\<=11) && ((currentY-aFacilityYpos8[j])\>=-11)) {  
if (arrayNumber != j) {  
//trace(arrayNumber + " arrayNumber");  
//trace(j+ " j");  
\_root.container\_mc.firstload[“instance”+arrayNumber].\_y = (\_root.container\_mc.firstload[“instance”+j].\_y+15);  
}  
}  
}  
}  
}  
function sameSpace9(arrayNumber, nodesLength, currentX, currentY) {  
for(j:Number = 0; j \<= nodesLength -1; j++) {;  
if (((currentX-aFacilityXpos9[j])\<=11) && ((currentX-aFacilityXpos9[j])\>=-11)) {  
if (((currentY-aFacilityYpos9[j])\<=11) && ((currentY-aFacilityYpos9[j])\>=-11)) {  
if (arrayNumber != j) {  
\_root.container\_mc.firstload[“instance”+arrayNumber].\_y = (\_root.container\_mc.firstload[“instance”+j].\_y+15);  
}  
}  
}  
}  
}
