Copy link to clipboard
Copied
What is the correct method to add TextFields to an Array? When I declare an Array for:
var myLabels:Array = new Array();
then attempt to populate it with TextFields, using:
var myLabels[i]:TextField = new TextField();
I get a syntac error. Is there another step, or a different method to use to assign it?
then use:
var myLabels:Array = new Array();
//var i:int = 0;
myLabels[i]=new TextField();
ie, this is problematic:
var myLabels[i]=new ANYTHING(); // is going to trigger an error
you're welcome.
and, if you read the error message carefully, it's pinpointing the error for you. ie, there's only one left bracket in your posted code. the actual problem (var) isn't explained because animate thinks you mean something like:
var xyz; myLabels[i] = new TextField();
and is unhappy it sees no xyz;
but, like most compilers, it is perfectly happy with (and allows multiple statements) on one line. only we humans have trouble reading code with multiple statements on the same
...Copy link to clipboard
Copied
you have several errors. use:
var myLabels:Array = new Array();
var i:int = 0;
myLabels[i]=new TextField();
Copy link to clipboard
Copied
The i value is coming from a loop, so its not undefined. But even:
var myLabels[0] = new TextField();
gives the error:
1086: Syntax error: expecting semicolon before leftbracket.
Copy link to clipboard
Copied
then use:
var myLabels:Array = new Array();
//var i:int = 0;
myLabels[i]=new TextField();
ie, this is problematic:
var myLabels[i]=new ANYTHING(); // is going to trigger an error
Copy link to clipboard
Copied
The myLabels Array is declared in frame1, then I'm attempting to add its members in frame2 in a loop, where i is incrementing from 0-3. In that loop:
var myLabels[i] = new TextField();
is what's giving the syntax error:
1086: Syntax error: expecting semicolon before leftbracket.
The error goes away if I comment out that line.
Copy link to clipboard
Copied
Ok, I see. I didn't need the extra var definition. It works after I noticed you omitted that, and I took it out. Thanks.
Copy link to clipboard
Copied
you're welcome.
and, if you read the error message carefully, it's pinpointing the error for you. ie, there's only one left bracket in your posted code. the actual problem (var) isn't explained because animate thinks you mean something like:
var xyz; myLabels[i] = new TextField();
and is unhappy it sees no xyz;
but, like most compilers, it is perfectly happy with (and allows multiple statements) on one line. only we humans have trouble reading code with multiple statements on the same line.