arrays - Using a loop to assign labels won't work in Actionscript 3. TypeError: Error #1010 -
i've used website many things , found lot of useful information has helped me create randomized quiz mostly. i'm trying make code efficient possible , has led me error.
i have created array uses .push function store existing buttons on stage array future use. code shown below sets label of each button correctly.
_buttons[0].label = xmldata.difficulty1.questions[num2].op1.text(); _buttons[1].label = xmldata.difficulty1.questions[num2].op2.text(); _buttons[2].label = xmldata.difficulty1.questions[num2].op3.text(); _buttons[3].label = xmldata.difficulty1.questions[num2].op4.text();
so naturally wanted make little more efficient , put these in loop. based on logic should work doesn't.
for (var i:number = 0; < 4; i++) { _buttons[i].label = xmldata.difficulty1.questions[num2].op[i+1].text(); }
this code should increment array counter of _buttons , set label each. mean it's first set of code in loop right? when run following error: typeerror: error #1010: term undefined , has no properties.
now know sure first set of code works have tested repeatedly decide put loop, fails. explain why? perhaps it's limitation of language itself? maybe i'm missing command?
try :
for (var i:number = 0; < 4; i++) { _buttons[i].label = xmldata.difficulty1.questions[num2]['op'+(i+1)].text(); }
.op[i+1]
tries access property called 1
under field called op
instead of op1
Comments
Post a Comment