Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 - Variable type definition

Explorer ,
Jul 18, 2014 Jul 18, 2014

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?

TOPICS
ActionScript
412
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jul 18, 2014 Jul 18, 2014

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

Maybe you can try:

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

Translate
Explorer ,
Jul 18, 2014 Jul 18, 2014

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

Maybe you can try:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 18, 2014 Jul 18, 2014

It seems to be working very good. Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 18, 2014 Jul 18, 2014
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines