1

我也在尝试每秒加载新消息,但是每次加载新消息时都会加倍,我想是因为计时器在执行 php 之前完成?所以我尝试添加

  if (checker != "" + idstored + "done") {
checker =  "" + idstored + "done";

这样一旦计时器完成,它就会更改检查器,以便当计时器重新启动并再次完成时它不会再次执行......但它停止检查所有新消息......任何提示?

var count:Timer = new Timer(1000, 1);
count.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete); 
count.start();

var checker;
function onTimerComplete(event:TimerEvent):void{
    if (checker != "" + idstored + "done") {
    checker =  "" + idstored + "done";

    var variables_cc:URLVariables = new URLVariables();
    var varSend_cc:URLRequest = new URLRequest("chat.php");
    varSend_cc.method = URLRequestMethod.POST;
    varSend_cc.data = variables_cc;
    var varLoader_cc:URLLoader = new URLLoader;
    varLoader_cc.dataFormat = URLLoaderDataFormat.VARIABLES;
    varLoader_cc.addEventListener(Event.COMPLETE, completeHandler_cc);

    function completeHandler_cc(event:Event):void{
        if (event.target.data.statusline == "is_new") {
              stored_id_txt.text = "" + event.target.data.stored_id;
              status_txt.text = "" + event.target.data.statusline;
              returnline.text = "" + event.target.data.returnBody;
              checker.text = checker;
              splitByDelimiter(event.target.data.returnBody);
              idstored = event.target.data.stored_id;
              checker = "refresh";
        } 
    }}
    // ready the last_refresh_time variable for sending to PHP
    variables_cc.requester = "chat_check";
    variables_cc.stored_id = idstored;
    varLoader_cc.load(varSend_cc);
    count.reset();
    count.start();
}
4

1 回答 1

0

您会收到错误,因为您有时会在之前的下载未完成时尝试开始新的下载。每隔 1 秒实时做一些依赖于延迟的事情是不明智的。你需要开始一些事情,等待它完成,然后再重新开始。

定时器启动后的 removeEventListener (在 onTimerComplete 函数内)并停止定时器并重置它。qddEventListener 到计时器并在数据下载后启动它(在 completeHangler_cc 函数中)。

于 2013-04-17T12:28:52.693 回答