sequencial movieclip name in AS3
I'm pretty unexperienced with Action Script but searched the forums extensively to try and find a solution to this simple problem.
I'm creating several copies of a MovieClip but I need the开发者_如何学编程m to have different names.
// this array gets several cities
var cities:Array = new Array(
{ nome:"london", pos_x:20, pos_y:10 },
{ nome:"nyc", pos_x:210, pos_y:210 }
);
// now i would loop the cities array and create a copy of city_img for each
var k:*;
for each (k in cities) {
var mov:city_img = new city_img(); // city_img is a movieclip
addChild(mov);
mov.x = k.pos_x;
mov.y = k.pos_y;
mov.id = i;
i++;
}
This code works but, as expected, mov
gets id=1. Even though two movieclips are drawn on stage.
Can anyone help me on assign different names for each movieclip?
Use name property no ?
// this array gets several cities
var cities:Array = new Array(
{ nome:"london", pos_x:20, pos_y:10 },
{ nome:"nyc", pos_x:210, pos_y:210 }
);
// now i would loop the cities array and create a copy of city_img for each
var k:*;
var i:int=0;
for each (k in cities) {
var mov:city_img = new city_img(); // city_img is a movieclip
addChild(mov);
mov.x = k.pos_x;
mov.y = k.pos_y;
mov.id = i;
mov.name=k.nome; // <-- here set the name of the movie clip
i++;
}
精彩评论