0

我对动作脚本非常陌生,但广泛搜索了论坛以尝试找到解决这个简单问题的方法。

我正在创建多个 MovieClip 副本,但我需要它们具有不同的名称。

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

此代码有效,但正如预期的那样,mov得到id=1。即使在舞台上绘制了两个电影剪辑。

谁能帮我为每个影片剪辑分配不同的名称?

4

1 回答 1

1

使用名称属性不?

// 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++;
}
于 2010-07-09T20:23:16.630 回答