代码之家  ›  专栏  ›  技术社区  ›  Frankie

AS3中的顺序movieclip名称

  •  0
  • Frankie  · 技术社区  · 14 年前

    我对动作脚本还没什么经验,但我在论坛上搜索了很多,试图找到解决这个简单问题的方法。

    我正在制作一部电影的几个副本,但我需要它们有不同的名字。

    // 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 回复  |  直到 14 年前
        1
  •  1
  •   Patrick    14 年前

    使用 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++;
    }