噢。给多少?80分可以吗?
毫秒,那是几乎不可能的。机器不准的,用0.1秒,还是比较精准了。
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.display.SimpleButton;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
public class TestWatch extends Sprite
{
/* 这个例子里面,要将FPS设置为80,将会更为精确些 */
/* 这是为什么,没有为什么,这是Adobe公司说的 */
private var showText : TextField;
private var timer : Timer;
private var minute : int;
private var second : int;
private var microSecond_100 : int;
private var timeShow :String;
public function TestWatch()
{
init();
createTextField();
////舞台上三个按钮
startButton.addEventListener(MouseEvent.CLICK,whenClickS);
pauseButton.addEventListener(MouseEvent.CLICK,whenClickP);
resetButton.addEventListener(MouseEvent.CLICK,whenClickReset);
}
private function init():void
{
microSecond_100=second=minute=0;
timer=new Timer(100,1);
timer.addEventListener(TimerEvent.TIMER,timeOut);
}
private function timeOut(event:TimerEvent):void
{
microSecond_100++;
judge();
timeShow=String(minute)+" 分:"+String(second)+" 秒:"+String(microSecond_100)+" 百微秒";
showText.text=timeShow;
timer.reset();
timer.start();
}
private function judge():void
{
if(microSecond_100 >= 10)
{
microSecond_100=0;
second++;
if(second >=60)
{
second=0;
minute++;
}
}
}
private function whenClickS(event:MouseEvent):void
{
timer.start();
}
private function whenClickP(event:MouseEvent):void
{
timer.stop();
}
private function whenClickReset(event:MouseEvent):void
{
timer.stop();
showText.text="";
microSecond_100=second=minute=0;
}
private function createTextField():void
{
showText=new TextField();
addChild(showText);
showText.width=200;
showText.selectable=false;
showText.x=100;
showText.y=50;
showText.text=" ";
}
}
}