Take the 2-minute tour ×

I have only been using ActionScript 3 for three days, so I'm a major newb, but I've used several other languages for most of my life.

I have the following code at frame one of the top layer:

var level:Array = new Array();
var level[0] = new Object();

I am getting the following error:

Scene 1, Layer 'levels', Frame 1, Line 2
1086: Syntax error: expecting semicolon before leftbracket.

I've looked at many examples which seem to be doing the same thing I'm doing, and I've also tried defining the object separately and then adding it to the array, with the same error. I've also searched for the answer, but all the questions I've found are a little different than this situation. Thanks in advance for any help or links.

share|improve this question
Basically, you've declared the level variable twice. the compiler should have thrown a conflict error but instead though it would be best to go off about a semicolon. Flash Professional is not a very good code editor. Take a look at either FlashDevelop (PC only) or Flash Builder (Cro$$ platform) if you would like a more acceptable code editor. –  TheDarkIn1978 Oct 25 '12 at 2:36
I'm a little embarrassed because I should have noticed my error before posting and I figured it out right after posting, but hopefully all of the great answers posted here will help someone else. Special thanks to pst for teaching me some new syntax. –  David W. Allor Oct 25 '12 at 17:48
don't forget to accept pst's answer as the correct one. –  TheDarkIn1978 Oct 25 '12 at 19:32
add comment

2 Answers

up vote 4 down vote accepted

The syntax/grammar production

var level[0] = new Object();

is invalid.

The var production expects a simple Identifier, not an expression1. The parser was roughly trying to treat the production as var level;[0] = ..; (but failed due to the missing semicolon, and would have failed anyway because [0] = ..; is an invalid production as well).


var level:Array = new Array();
level[0] = new Object(); // no "var" here so it is a valid grammar production

or, more concisely:

var level:Array = [{}];  // using Array and Object literal notations

1 See AS3.g for that ANTLR production rules. Alternatively, for ECMAScript (from which AS derives), see 12.2 Variable Statement from ES5-Annotated and note that it requires an "Identifier" followed by an optional initializer (=) or another declaration (,) or end of statement (;).

share|improve this answer
add comment

Only is

level[0] = {};


share|improve this answer
add comment

Your Answer


