어떻게 무시합니까?
적절하게 시간을 계산하는 스크립트에서도 날짜 클래스를 사용하기 만하면됩니다.
- 가 첫 번째 프레임에이 코드를 추가
- 이 minText, secText, MilText라는 이름의 3 텍스트 상자를 추가 새로운 AS3 문서 및 버튼이라고 start_btn 만들기 :
var에 STT : INT를; //이 변수를 사용하여 시작 시간을 타임 스탬프로 추적합니다.
var myTimer : Timer = new Timer (1); // 이것은 우리의 타이머입니다
var starttime:Date; // pretty obvious
var actualtime:Date; // pretty obvious
myTimer.addEventListener(TimerEvent.TIMER, stopWatch); // we start counting with this counter
start_btn.addEventListener(MouseEvent.CLICK, startClock); // add a button listener to start the timer
function startClock(event:MouseEvent):void
{
starttime = new Date(); // we get the moment of start
stt = int(starttime.valueOf().toString()); // convert this into a timestamp
myTimer.start(); // start the timer (actually counter)
}
function stopWatch(event:TimerEvent):void
{
actualtime = new Date(); // we get this particular moment
var att:int = int(actualtime.valueOf().toString()); // we convert it to a timestamp
// here is the magic
var sec:int = (Math.floor((att-stt)/1000)%100)%60; // we compute an absolute difference in seconds
var min:int = (Math.floor((att-stt)/1000)/60)%10; // we compute an absolute difference in minutes
var ms:int = (att-stt)%1000; // we compute an absolute difference in milliseconds
//we share the result on the screen
minText.text = String(min);
secText.text = String(sec);
milText.text = String(ms);
}
왜 Date 클래스의 기능을 사용하지 않고 시간 소인이 필요합니까?
두 사건 사이의 차이를 계산하려면 당신은 아마이을 사용하기 때문에 : 당신의 시작 이벤트가 57'th 초에 발생하고 종료 이벤트가 일어나는 경우 매우 잘못
endEvent.seconds - startEvent.seconds
두 번째로 17 초, 20 초 대신에 -40 초를 얻는다.
'flash.utils.getTimer()이 내가 가지고있는'Date' 클래스 – BadFeelingAboutThis