I am trying to use a for loop to increment the creation of a movieClip and adds the movie clip to the stage.
Something like this:
for (var i:int = 0; i<6;i++){
var ball + i:MovieClip = new Ball();
addChild(ball + i);
ball + i.x = 470;
ball + i.y = 130;
}
Am I going about this incorrectly?
I am getting the following error:
C:\PATH TO MY /ASFILE.as, Line 64 1086: Syntax error: expecting semicolon before plus.
I think a good way of doing this is by creating an
Arraycontaining the newly created balls.You store a reference of every
ballin thearrayBallsso you don’t have to create a new var each time. By statingball = new Ball()you’re ‘erasing’ the previous stored value and simply create a new one. Later on you can loop through yourArrayand do whatever you like with it. Like soOr something like this
Hope this is what you were looking for.