I have used this website for many things and have found very useful information which has helped me to make a random quiz . I am trying to make the code as efficient as possible and he has inspired me to this error.
I have created an array that uses the .push function to store the current button on the platform for future use. The codes below set the 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 I wanted to make it a bit more efficient and put them in the loop. This will work based on logic but not. For
(var i: number = 0; i <4; i ++) {_buttons [i] .label = xmlData.difficulty1. Question [nUM2] .op [i + 1] .text (); }
This code should only increase the _buttons array counters and set the labels for each. I mean is this the first set of code in the right of the loop only? But when I run it I get the following error: TypeError: Error # 1010: A word is undefined and does not have any properties.
Now I'm sure its first set code works as I have tested it repeatedly, but as soon as I put it for loop, it fails. Can anyone explain why? Maybe it's a limitation of language? Maybe I'm missing a command? Try
:
(Var i: number = 0; I & lt; 4; i ++) {_buttons [i] .label = xmlData.difficulty1.questions [num2] ['op' + (i + 1)] Text (); }
instead of
. op
under a field called .op [i + 1] op1
No comments:
Post a Comment