AS3计时器比php更快

时间:2013-04-17 06:55:32

标签: actionscript-3 flash timer

我每秒都尝试加载新邮件,但每次加载新邮件时都会加倍,我想是因为计时器在执行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();
}

1 个答案:

答案 0 :(得分:0)

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

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