Skip to main content
Inspiring
July 18, 2014
Answered

AS3 - Variable type definition

  • July 18, 2014
  • 3 replies
  • 479 views

I have this code:

var arr: Array;

arr = new Array(blue, brown, green, pink, red);

var type: arr[0] = new arr[0];


(blue, brown, green, pink and red are MovieClips)


And I get this error:

Syntax error: Expecting semicolon before leftbracket.


What exactly is wrong?

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer kfitfk

You can't use arr[0] for the type.

Maybe you can try:

var type:* = new arr[0] as arr[0];

3 replies

kfitfkCorrect answer
Inspiring
July 18, 2014

You can't use arr[0] for the type.

Maybe you can try:

var type:* = new arr[0] as arr[0];

gibsyAuthor
Inspiring
July 18, 2014

It seems to be working very good. Thanks.

Amy Blankenship
Legend
July 18, 2014

Note that this is what Interfaces are for. So you get type information without being tied to a specific implementation.