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