PDA

View Full Version : simple for loop question.


drumn4life0789
07-01-2008, 04:27 AM
I have this code

enter_btn.onRelease = function () {
bracket1 = team1;
bracket2 = team2;
bracket3 = team3;
bracket4 = team4;
}


bracket1 is a dynamic text box and team1 is an input text box. When the user fills in the team text box and clicks the enter button it will fill in the bracket text box. This is very simple and it works fine. Right now I am ok with this code but I am just trying to do something on the small scale as of now, so I can learn it for my bigger project I am doing.

I would like to use a for loop because the values of the bracket and team will soon be up to 32 and it will be alot of waisted space and time to type them all out. I know I can use for loop but for some reason i just cant figure out why its not working for me.


enter_btn.onRelease = function () {
for (i=1; i<=4; i++) {
["bracket"+i] = ["team"+i];
}
}

ASWC
07-01-2008, 05:32 AM
You need the right scope and then you need to assign the text and not the input field:
enter_btn.onRelease = function () {
for (i=1; i<=4; i++) {
_level0["bracket"+i] = _level0["team"+i].text;
}
}
I really don't see how you can make this work:
enter_btn.onRelease = function () {
bracket1 = team1;
bracket2 = team2;
bracket3 = team3;
bracket4 = team4;
}
You assign the input field "team1" instead of the text "team1.text" and you say it's working great... I must have a different Flash version for me it never works like that....

drumn4life0789
07-01-2008, 07:03 AM
It works because I have bracket1 team1 and so on written into the var field. So it AS automatically links those words to that input text field.