我已经设置好了,所以我可以按两次空格键来设置计时器持续时间来重复一个影片剪辑。我想以另一个影片剪辑的一半持续时间重复第二个影片剪辑。所以对于每个循环它循环两次。这是我尝试过的:
var timeStart:Number;
var loopDuration:Number;
var timeLastLoop:Number;
var rando80:Number;
var rando802:Number;
var rando8:Number;
var randoy:Number;
var halfduration:Number;
var randomImage:Bitmap;
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onKeyDown(e:KeyboardEvent):void {
if (e.keyCode == Keyboard.SPACE) {
if (!timeStart) { // First time SPACE is hit
timeStart = getTimer();
} else { // Second time SPACE is hit
loopDuration = getTimer() - timeStart; // set the loop duration
halfduration = (getTimer() - timeStart) *.5;
timeStart = NaN; // reset the start time
loop();
}
}
}
function onEnterFrame(e:Event):void {
rando8 = Math.floor(Math.random() * 7);
rando80 = Math.floor(Math.random() * 70);
randoy = Math.floor(Math.random() * -1000);
rando802 = Math.floor(Math.random() * 70);
if ( timeLastLoop && halfduration) {
if (getTimer() >= timeLastLoop + halfduration) { // if it's time to loop
circleThump2.gotoAndPlay(1);
}
}
if (loopDuration && timeLastLoop) {
if (getTimer() >= timeLastLoop + loopDuration) { // if it's time to loop
loop();
}
}
}
function loop():void {
timeLastLoop = getTimer();
circleThump.gotoAndPlay(1);
MovieClipMan.gotoAndPlay(rando80);
hotdog.gotoAndPlay(rando80);
MovieClipMan.y = randoy;
MovieClipMan2.gotoAndPlay(rando80);
movieClipColor.gotoAndStop(rando8);
MovieClipMan2.y = randoy;