1
votes

I get following error:

1084: Syntax error: expecting identifier before var.

this my code, I try a lot of search on Google this error, but don't have. How I can fix it?

code:

 public function setAchievements(Subject:Array, Desc:Array, Coins:Array, Score:Array, Completed:Array) : *
  {
(error line here)      for(var achievement:Achievement = null,var color:Color = null; this.achievements_mc.achievements_content.content_mc.numChildren > 0; )
     {
        this.achievements_mc.achievements_content.content_mc.removeChildAt(0);
     }
     var x:* = 0;
     var y:* = 0;
     for(var i:int = 0; i < Subject.length; i++)
     {
        achievement = new Achievement();
        achievement.Subject_txt.text = Subject[i];
        achievement.Description_txt.text = Desc[i];
        achievement.Coins_txt.text = String(Coins[i]);
        achievement.Score_txt.text = String(Score[i]);
        if(Completed[i])
        {
           color = new Color();
           color.brightness = -0.4;
           achievement.transform.colorTransform = color;
           achievement.icon.visible = true;
        }
        achievement.x = x;
        achievement.y = y;
        y = y + 125;
        this.achievements_mc.achievements_content.content_mc.addChild(achievement);
     }
  }
1
You probably are not allowed to declare 2 variables in the first section of the for loop. Try declare achievement and color before the loop statement. - Organis
i try this, but then a not work - ShlomiUserAS3
What are you trying to achieve exactly with that error line? Even if it worked it would only remove the first thing added into content_mc. Each addChid creates on a new layer so you're deleting layer 1 (since at position 0) of the MovieClip. Is that what you want? Or maybe you want to empty the entire MClip? - VC.One

1 Answers

2
votes

The correct syntax of for / for each statement in AS3 is:

for each (var yourvariable:TypeOfVariable in list of objects)

i.e.

for (var currObject:Person in listPerson)

(where your listPerson is an ArrayCollection)

Another correct syntax is:

for (var i:int; i < list.length(); i++)

but you have written:

for(var achievement:Achievement = null,var color:Color = null;
this.achievements_mc.achievements_content.content_mc.numChildren > 0;)

This isn't a correct syntax, because ther's no link between loop variables and exit condition

Maybe you want to write

for each(var achievement:Achievement in
this.achievements_mc.achievements_content.content_mc.numChildren)

and then you can initialize

var color:Color = 0 or another value linked to iteration