针对具有相同的实例名称的多个影片剪辑多个、实例、影片剪辑、名称

2023-09-09 21:52:33 作者:格式化自己只为删除你〃

在舞台上,我有3个影片剪辑谁具有相同的实例名,这是

On the stage, I have 3 MovieClips who have the same instance name, which is

zeroMC

,但所有三个都是不同的影片剪辑的实例。第一zeroMC是blank1的一个实例中,第二zeroMC是BLANK2的一个实例,并且所述第三zeroMC是blank3的一个实例。

but all three are an instance of different MovieClips. The first zeroMC is an instance of blank1,the second zeroMC is an instance of blank2 and the third zeroMC is an instance of blank3.

我要让所有三个影片剪辑gotoAndStop在2,但是当我做

I want to make all three movieclips gotoAndStop at 2, but when I do

zeroMC.gotoAndStop(2);

只有一个人去,并停止在2。我也尝试过

only one goes to and stops at 2. I also tried

var containers = [zeroMC, zeroMC, zeroMC];

for (var i:int = 0; i<containers.length; i++) {
    containers[i].gotoAndStop(2);
}

但也只是做了一个zeroMC gotoAndStop在2如何获得所有三gotoAndStop在2?

but that also only made one zeroMC gotoAndStop at 2. How do I get all three to gotoAndStop at 2?

推荐答案

您只能有一个引用到舞台上的影片剪辑,所以你不能因为同时当你希望更新所有三个。

You can only have one reference to an on-stage MovieClip, so you will not be able to update all three as simultaneously as you hope.

我建议你存储在电影剪辑数组并添加影片剪辑来使用ActionScript(如果你没有的话)的阶段:

I'd recommend storing your MovieClips in an Array and adding the MovieClips to the stage using ActionScript (if you aren't already):

var _movieClips:Array = new Array();

_movieClips.push(new ZeroMC()); // in this case 'ZeroMC' will need to be the Class name of your MovieClip
_movieClips.push(new ZeroMC());
_movieClips.push(new ZeroMC());
for (var loop:int=0;loop<_movieClips.length;loop++) {
    addChild(_movieClips[loop]);
    _movieClips[loop].gotoAndStop(2); // you may want to do this in your game loop, or wherever it is you need your MovieClips to go to frame 2. You will need to LOOP through them though...
}