PDA

View Full Version : Btn Script in a loop


BrownEye
01-18-2006, 06:05 PM
I have 6 buttons on my stage, named btn1_mc, btn2_mc, so on...

I have those 6 buttons in an array.

I want to write a for loop I think so that I only have to write the script for the buttons 1 time. Meaning I don't want to copy and paste all the code for btn1_mc, and change out btn1_mc with btn2_mc and so on.

So how do I write the loop so that I don't have redundant code.

Did that all make sense? Here is what I have right now...

------------------------------------------------

Vbtnarray = new Array();
Vbtnarray[0] = btn1_mc;
Vbtnarray[1] = btn2_mc;
Vbtnarray[2] = btn3_mc;
Vbtnarray[3] = btn4_mc;
Vbtnarray[4] = btn5_mc;
Vbtnarray[5] = btn6_mc;
//
i = 0;
for (i; i<Vbtnarray.length; i++) {
VbtnName = Vbtnarray[i];
trace(VbtnName);
}
VbtnName.onRollOver = function() {
trace(VbtnName+"rollover")
}

------------------------------

But the only button that works is the last button in the array. I'm sure I am just having a brain issue at the moment.

Thanks.

Flash Gordon
01-18-2006, 06:07 PM
see my signiture for problems with loops