开发者

sequencial movieclip name in AS3

开发者 https://www.devze.com 2023-01-06 11:41 出处:网络
I\'m pretty unexperienced with Action Script but searched the forums extensively to try and find a solution to this simple problem.

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++;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号