我有5个MovieClips(5个简单的按钮),我需要他们从第二帧开始每4秒钟播放其中一个。我做错了什么?感谢。
var clipArray:Array = new Array();
clipArray[0] = loader.button_01_mc.gotoAndPlay (2);
clipArray[1] = loader.button_02_mc.gotoAndPlay (2);
clipArray[2] = loader.button_03_mc.gotoAndPlay (2);
clipArray[3] = loader.button_04_mc.gotoAndPlay (2);
clipArray[4] = loader.button_05_mc.gotoAndPlay (2);
var clipTimer:Timer = new Timer(4000);
clipTimer.addEventListener(TimerEvent.TIMER, playClips);
function playClips(event:TimerEvent):void
{
//Chooses a random clip in your array
var randomClip:int = Math.random() * clipArray.length;
}
clipTimer.start();
答案 0 :(得分:2)
您需要在该数组中存储对影片剪辑的引用,而不是gotoAndPlay方法调用的结果(无效)。然后使用随机索引从数组中获取一个剪辑,并在其上调用gotoAndPlay方法。
var clipArray:Array = new Array();
clipArray[0] = loader.button_01_mc;
clipArray[1] = loader.button_02_mc;
clipArray[2] = loader.button_03_mc;
clipArray[3] = loader.button_04_mc;
clipArray[4] = loader.button_05_mc;
var clipTimer:Timer = new Timer(4000);
clipTimer.addEventListener(TimerEvent.TIMER, playClips);
function playClips(event:TimerEvent):void {
var randomClip:int = Math.floor(Math.random() * clipArray.length);
var mc:MovieClip = clipArray[randomClip];
mc.gotoAndPlay(2);
}
clipTimer.start();