PDA

View Full Version : For Loop woes...



Gmoney
August 9th, 2004, 05:01 PM
I know there is a for loop topic just below this one, but I think my question is different enough to not warrant flaming. My first question is this. why does the first not work but the second does ? This one traces undefined.


for (i=1; i<100; i++) {
myArray[i] = i;
trace(myArray[i]);
}


This one traces:

undefined
undefined
etc.



for(i=0; i<10; i++) {
array [i] = (i + 5)*10;
trace(array[i]);
}


This one traces

50
60
70
80
90
100
110
120
130
140


My other question, very related, is this: How do you address different MCs with numbers using loops. What I mean is, how would you write a multiple (more than two) hit detection script.

Mediamonkey
August 10th, 2004, 06:09 AM
no problem, works just fine with me.


i = 0;
myArray = new Array();
array = new Array();

for (i=1; i<100; i++) {
myArray[i] = i;
trace(myArray[i]); // outputs 1-99
}

for(i=0; i<10; i++) {
array [i] = (i + 5)*10;
trace(array[i]); // ouputs 50-140
}

Mediamonkey
August 10th, 2004, 06:12 AM
My other question, very related, is this: How do you address different MCs with numbers using loops. What I mean is, how would you write a multiple (more than two) hit detection script.
for example mc_1, mc_2, mc_3 ?


for (var i=1; i<=3; i++) {
trace(this["mc_"+i]._name + " called");
}