change movieclip instance name in runtime

末鹿安然 提交于 2020-01-06 13:56:50

问题


I'm trying change movieclip instance name in runtime, with name property but I have error

Error #2078: The name property of a Timeline-placed object cannot be modified. 

I tried to create new movieclip in runtime asign my old movie clip and change name property but I have same error...

and is any way to change instance name of movieClip in runtime?


回答1:


So far the only workaround I've found is to use an array:

import flash.display.MovieClip;
import flash.geom.ColorTransform;

var t:Boolean; // for toggle function
var square: Array = new Array();
var changeColor: ColorTransform = new ColorTransform();

for (var i: int = 0; i < 5; ++i) {
    var rect: MovieClip = new MovieClip();
    rect.graphics.beginFill(0xaaaaaa);
    rect.graphics.drawRect(10, 10, 50, 50)
    addChild(rect);
    rect.x = 75 * (i + 1);
    rect.y = 100;

    square.push(rect)

}

// This toggles the middle square up and down, and gray to red.
square[2].addEventListener(MouseEvent.CLICK, toggle);

function toggle(event: MouseEvent): void {

    if (!t) {

        changeColor.color = 0xff00000;
        square[2].transform.colorTransform = changeColor;

        square[2].y = 50;

    } else {

        changeColor.color = 0xaaaaaa;
        square[2].transform.colorTransform = changeColor;

        square[2].y = 100;
    }

    t=!t;
}


来源:https://stackoverflow.com/questions/26990906/change-movieclip-instance-name-in-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!