Skip to main content
Inspiring
July 18, 2014
Answered

AS3 - Variable type definition

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.
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];

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];

Translate
gibsyAuthor
Inspiring
July 18, 2014

It seems to be working very good. Thanks.

Translate
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.

Translate