简体   繁体   中英

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.

Ex of what i want in frame 2 actions:

1st time: var CountDown:Number = 3;

2nd time: var CountDown:Number = 2,95;

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

4th ...

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)         

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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