PeaceLoveFamily
PeaceLoveFamily

Reputation: 93

multiple shape objects with as3

hey i want to be able to create multiple shapes and store them perhaps in an array to be able to dynamically move them and change them. is there a way to have a shape object and store it an array? so that i can do something like shapeArray[0].x =100 current code

for(var i=0; i<10; i++){
var sprite:Sprite=new Sprite();

sprite.graphics.lineStyle(1)
sprite.graphics.drawCircle(0,0,10)
sprite.graphics.endFill();
addChild(sprite)
}

many thanks

Upvotes: 0

Views: 519

Answers (1)

Engineer
Engineer

Reputation: 48813

There is Vector class, you could use:

var shapeArray:Vector.<Sprite> = new Vector.<Sprite>();
for(var i=0; i<10; i++){
    var sprite:Sprite=new Sprite(); 
    sprite.graphics.lineStyle(1)
    sprite.graphics.drawCircle(0,0,10)
    sprite.graphics.endFill();
    addChild(sprite);

    shapeArray.push( sprite );
}

Upvotes: 1

Related Questions