我正在尝试在运行时更改movieclip实例名称,使用name
属性但我有错误
Error #2078: The name property of a Timeline-placed object cannot be modified.
我试图在运行时创建新的movieclip,将我的旧影片剪辑更改为更改名称属性,但我有同样的错误......
并且可以在运行时更改movieClip的实例名称吗?
答案 0 :(得分:0)
到目前为止,我发现的唯一解决方法是使用数组:
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;
}