下面的代码从一组影片剪辑中随机添加一个影片剪辑到舞台。将影片剪辑添加到舞台后,它会通过回显相应的声音剪辑在 x 轴上水平移动。但我的问题是,舞台上添加的任何电影剪辑都只播放相同的声音剪辑。它发生的原因当然是因为这条线:
var mc:MovieClip = new enemies[printArray[p]];
谁能告诉我如何单独控制属于“var mc”的每个电影剪辑的行为。而不是写这样的东西:
if(mc.x <= -100) { Enem1Timer.stop()} else if(mc.x <= 570){ Enem1Timer.start() }
有没有办法像这样写:
if(Enem1.x <= -100).....
任何帮助都是最受欢迎的。提前谢谢。
import flash.utils.Timer;
import flash.display.MovieClip;
var sound1:Letter1 = new Letter1();
var sound2:Letter2 = new Letter2();
var sound3:Letter3 = new Letter3();
var sound4:Letter4 = new Letter4();
var sound5:Letter5 = new Letter5();
var sound6:Letter6 = new Letter6();
var printArray:Array = [0, 1, 2, 3, 4, 5];
var enemies:Array = [Enem1, Enem2, Enem3, Enem4, Enem5, Enem6];
for(var n:int = 0; n <= 6; n++)
{
var randNo:int = int(Math.random() * 6);
printArray.push(randNo);
}
var Enem1Timer:Timer = new Timer(1000, 1);
Enem1Timer.addEventListener(TimerEvent.TIMER, playA1);
function playA1(e:TimerEvent):void
{sound1.play();}
for(var p:int = 0; p < printArray.length; p++)
{
trace(printArray[p]);
var mc:MovieClip = new enemies[printArray[p]];
addChild(mc);
mc.x = 600; mc.y = 200;
stage.addEventListener(Event.ENTER_FRAME, loop)
function loop(e:Event){
if(mc.x <= -100) { Enem1Timer.stop()} else if(mc.x <= 570){ Enem1Timer.start() }
mc.x -= 3;
}}