我正在尝试构建一个倒计时器,它使用一个名为ResponseTime.txt的文本文档中包含的时间。我没有收到任何错误消息,但它无法正常工作。我找不到问题。
{
addEventListener('enterframe', callback_handler)
function callback_handler(e:Event):void {
var StartTime:URLLoader = new URLLoader();
StartTime.dataFormat=URLLoaderDataFormat.VARIABLES;
StartTime.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
StartTime.load(new URLRequest("ResponseTime.txt"));
var today:Date = new Date();
var currentTime = today.getTime();
var targetDate:Date = new Date();
var timeLeft = StartTime.data - currentTime;
var sec = Math.floor(timeLeft/1000);
var min = Math.floor(sec/60);
sec = String(sec % 60);
if(sec.length < 2){
sec = "0" + sec;
}
min = String(min % 60);
if(min.length < 2){
min = "0" + min;
}
if(timeLeft > 0 ){
var counter:String = min + ":" + sec;
time_txt.text = counter;
}else{
var newTime:String = "00:00";
time_txt.text = newTime;
}
}
}
}
感谢。
答案 0 :(得分:0)
您正在调用onLoaded
中的加载方法,这是完成加载时的回调。所以加载器实际上从未开始加载。
function onLoaded(e:Event):void {
StartTime.load(new URLRequest("ResponseTime.txt"));
}
只需在回调之外启动加载。