作者:万承裕常明 | 来源:互联网 | 2023-05-18 04:12
I am a noob to AS3 so excuse me, please.
我是AS3的菜鸟,请原谅我。
I have a timer on my app that I am trying to use as a stop watch, What I would like to do is start it at a specified time not always at 0?
我在我的应用程序上有一个计时器,我试图用作秒表,我想做的是在指定的时间启动它并不总是在0?
I would like the user to enter in a text box a value of 1 to 99 and the timer starts from there entered value.
我希望用户在文本框中输入值1到99,并且计时器从输入的值开始。
Thanks in advance.
提前致谢。
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
var customtime:int;
clock.text = "00:00";
var myTimer:Timer = new Timer(1000,0);
myTimer.addEventListener(TimerEvent.TIMER, stopwatch);
function stopwatch(event:TimerEvent):void
{
clock.text = convert_time(myTimer.currentCount);
}
start_btn.addEventListener(MouseEvent.CLICK, startClock);
stop_btn.addEventListener(MouseEvent.CLICK, stopClock);
reset_btn.addEventListener(MouseEvent.CLICK, resetClock);
setTime_btn.addEventListener(MouseEvent.CLICK, setCustomTime);
function startClock(evt:MouseEvent):void
{
myTimer.start();
}
function stopClock(evt:MouseEvent):void
{
myTimer.stop();
}
function resetClock(evt:MouseEvent):void
{
myTimer.reset();
clock.text = "00:00";
}
function setCustomTime(evt:MouseEvent)
{
var t1:int = int(setTimeTxt.text)*60;
clock.text = convert_time(t1);
customtime = t1;
}
function time_update(t1:int):int
{
var t2:int=t1*60;
return t2;
}
function convert_time(currentAmountSecs:int):String
{
var minutes:int = Math.floor(currentAmountSecs / 60);
var seconds:int = currentAmountSecs % 60;
var prependString:String = "";
if ( minutes <10 )
{
prependString = "0";
}
var prependStringsec:String = "";
if ( seconds <10 )
{
prependStringsec = "0";
}
return prependString + minutes + ":" + prependStringsec + seconds;
}
1 个解决方案