AS3中的顺序动画片段名称

时间:2010-07-09 20:14:34

标签: flash actionscript-3 movieclip

我对Action Script缺乏经验,但在论坛上广泛搜索,试图找到解决这个简单问题的方法。

我正在创建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 。即使在舞台上画了两个动画片段。

任何人都可以帮助我为每个动画片段指定不同的名称吗?

1 个答案:

答案 0 :(得分:1)

使用name属性否?

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