转换字符串值到影片剪辑在AS 3.0影片剪辑、字符串值、AS

2023-09-08 15:05:42 作者:撩污酷浪野

我想转换成字符串数组影片剪辑这已经在舞台上存在的名称。

I am trying to convert an array of string to MovieClip names which already exist on stage.

这是我怎么做的,但美国能源部鼻涕似乎工作。 我有11个影片剪辑在舞台上。它们的实例名是bmc1,BMC2等。 所有这些BMC影片剪辑是一个名为bars_mc夹里。因此,这是我如何编码它现在。

THis is how I am doing it but doe snot seem to work. I have 11 movieclips on stage. THeir instance names are "bmc1", "bmc2" and so on. All these BMC movie clips are inside a clip called "bars_mc". So this is how I am coding it right now.

var myBtnArray = ['bmc1', 'bmc2', 'bmc3', 'bmc4', 'bmc5', 'bmc6', 'bmc7', 'bmc8', 'bmc9', 'bmc10', 'bmc11'];
for each (var btn in myBtnArray){
    bars_mc.MovieClip(getChildByName(btn)).gotoAndPlay('open');
}

这是行不通的。 我曾尝试这样做的:

This does not work. I have tried doing:

this[btn]

这也没有工作。 这是codeD在AS 3.0。

That also didnt work. This is being coded in AS 3.0.

需要有人T0帮我找出正确的方式将字符串转换为影片剪辑。

Need someone t0 help me figure out the right way to convert strings to MOvieclips.

鸭precuiate你的帮助。

Apprecuiate your help.

推荐答案

我认为这个问题很可能是你已经添加了影片剪辑投错了地方,因为虽然有对对象bars_mc属性影片剪辑。

I think the problem is likely that you've added the MovieClip cast in the wrong place, as though there were a property MovieClip on the object bars_mc.

这个例子涉及一个额外的行,但应该是一个更清楚一点:

This example involves an extra line but should be a bit clearer:

var myBtnArray = ['bmc1', 'bmc2', 'bmc3', 'bmc4', 'bmc5', 'bmc6', 'bmc7', 'bmc8', 'bmc9', 'bmc10', 'bmc11'];
for each (var btn:String in myBtnArray) {
    var btnClip:MovieClip = bars_mc[btn] as MovieClip;
    btnClip.gotoAndPlay('open');
}

和一个版本更接近你原来是:

And a version closer to your original would be:

var myBtnArray = ['bmc1', 'bmc2', 'bmc3', 'bmc4', 'bmc5', 'bmc6', 'bmc7', 'bmc8', 'bmc9', 'bmc10', 'bmc11'];
for each (var btn:String in myBtnArray) {
    MovieClip(bars_mc[btn]).gotoAndPlay('open');
}