PDA

View Full Version : looping through a button array



j0se
September 6th, 2003, 07:10 PM
hi all,

i have a bunch of buttons (with textboxes in them) on the stage, each called butt1, butt2, butt3, butt4 and i want to loop through them but i'm unsure how to target their text property inside the loop

this is what i have:

butt1.text = "button1";
butt2.text = "button2";
.
.
.

this is what i want to achieve:


// loop through the butonCount
for (i=1; i'<'buttonCount; i++) { //excuse the quotation binding the less-than sign

butt[i].text = "button" + i;

}

it's the butt[i] bit that i'm unsure about

i tried holding the name in a var and then targetted its text prop like:

theButton = "butt" + i ;
theButton.text = "button" + i;

but that doesn't work (i guess it;s just a variable value and as such it has no properties

do i need to create a button array (?)

thanks all

:crazy:

claudio
September 6th, 2003, 08:27 PM
nbuttons = 3;
for (var i = 1; i<=nbuttons; i++) {
this["butt"+i].text = "button"+i;
}

j0se
September 7th, 2003, 01:47 PM
cheers for that!

i have a second problem though:

i have a button the the stage, with an instance name of: "butt1"

the button itself lives inside a movieclip, where it is called thisButton (so i can do things like: thisBUtton.onRelase...)

when flash runs and I click the button I want to output the button's insance name on the stage (i.e. butt1) but i'm only getting the button's instance name in it's own movie

this._name = thisButton

is the name i want stored in a separate property?

edit: sorry - i realise that the problem is that the button code is inside the mc itself, where the button's name is thisButton

sorry again and thanks for the previous help!

claudio
September 7th, 2003, 02:41 PM
welcome ;)