简体   繁体   English

AS3帧加载减少了倒计时时间

[英]AS3 on frame load reduce Countdown time

I have the following countdown that will send the player to another frame if countdown equals 0. I need to update the code to reduce this countdown in 0,05 secs every time the frame is loaded. 我具有以下倒数计时,如果倒数等于0,则会将播放器发送到另一帧。我需要更新代码以在每次加载框架时在0.05秒内减少此倒数。

Ex of what i want in frame 2 actions: 在第2帧动作中我想要的是:

1st time: var CountDown:Number = 3; 第一次:var CountDown:Number = 3;

2nd time: var CountDown:Number = 2,95; 第二次:var CountDown:Number = 2,95;

3rd time: var CountDown:Number = 2,90; 第3次:var CountDown:Number = 2,90;

4th ... 4号...

can you please help me?? 你能帮我么??

Tks a lot!! 非常感谢!

Code: 码:

import flash.events.MouseEvent;
stop();

var fl_SecondsToCountDown_2:Number = 3;
var fl_CountDownTimerInstance_2:Timer = new Timer(1000, fl_SecondsToCountDown_2);


fl_CountDownTimerInstance_2.addEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler_2);
fl_CountDownTimerInstance_2.start();

function fl_CountDownTimerHandler_2(event:TimerEvent):void
{
//trace(SecondsToCountDown_2 + " seconds");
fl_SecondsToCountDown_2--;
if(fl_SecondsToCountDown_2 == 0){
gotoAndStop ("lost");
}
}

I'm not sure if I understood what you want but you can try this : 我不确定我是否了解您想要什么,但是您可以尝试以下操作:

1st frame : 第一帧:

I created a button just to go to the 2nd frame ( I didnt know how you go to your 2nd frame ) : 我创建了一个仅用于转到第二帧的按钮(我不知道您如何转到第二帧):

import flash.events.MouseEvent

btn.addEventListener(MouseEvent.CLICK, btn_on_Press)
function btn_on_Press(e:MouseEvent){
    gotoAndPlay(2)
}

stop()

2nd frame : 第二帧:

// if count_down didnt exist, we create it
if(!count_down) var count_down:Number = 3   
else count_down -= 0.05                         

// sometimes the operation give us result like this : 2.9000000000000004 so we should fixe decimals
trace(count_down.toFixed(2))        

// go tp your "lost" frame
if(count_down <= 0) gotoAndStop('lost')
// return to 1st frame
else gotoAndStop(1)         

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM