本文介绍了在运行时更改movieclip实例名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在运行时更改带有name
属性的movieclip实例名称,但出现错误
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.
我试图在运行时创建新的movieclip,将旧的电影剪辑分配给我,并更改name属性,但是出现相同的错误...
I tried to create new movieclip in runtime asign my old movie clip and change name property but I have same error...
并且有什么方法可以在运行时更改movieClip的实例名称吗?
and is any way to change instance name of movieClip in runtime?
推荐答案
到目前为止,我发现的唯一解决方法是使用数组:
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;
}
这篇关于在运行时更改movieclip实例名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!