0

Though coding, I must make many copies of the same MovieClip to be placed on the stage, each to be manipulated code-wise on its own

For instance, I have a MovieClip named MC and I wish to have 99 copies of ít loaded onto the stage, each in a different x coordinate. What should I do?

I think on doing this:

Step 1: in the library, turning MC into a class

Step 2: placing the following code in the scene's script

var MyArray:Array = new Array

for (var i:int = 0; i<99;i++)
{
var MCInstance:MC = new MC
MC Instance = MyArray[i]
MovieClip.(MyArray[i]).x = i*30
}

Would that make sense?

Incognito
  • 331
  • 1
  • 5
  • 14

2 Answers2

2

That's probably the right idea, your syntax is just a little off. Try this:

var myArray:Array = [];

for (var i:int = 0; i < 99;i++)
{
    var mc:MC = new MC();
    myArray[i] = mc;
    mc.x = i * 30
}

AS3 style conventions: use lowerCamelCase for variable names, don't omit constructor parens even though they are optional, and create arrays using literals (source).

Aaron Beall
  • 49,769
  • 26
  • 85
  • 103
1

You could push each MovieClip to an Array after adding it to the Stage.

var myArray = [];
for(var i:int = 0; i < 99; i++)
{
    var myMc:MC = new MC();
    addChild(myMc);
    myMc.x = myMc.width * i + 2;
    myMc.y = 10;
    myArray.push(myMc);
}
gabriel
  • 2,351
  • 4
  • 20
  • 23
Danish Ajaib
  • 83
  • 10