希望这会有所帮助...使用计时器检查舞台上的交互,并将 URLLoader 指向您的 Web 服务域上的测试文件,以检查一切是否正常运行。location.reload
如果是这样,请刷新在 javascript 上调用 a 。
package {
import flash.display.Stage;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.events.TimerEvent;
import flash.events.TouchEvent;
import flash.external.ExternalInterface;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.utils.Timer;
public class TimeoutRefresh {
private var tt:Timer;
private var online:Boolean;
private var ldr:URLLoader;
public function TimeoutRefresh(stageRef:Stage, minutes:int) {
//set up timer
tt = new Timer(minutes * 60 * 1000);
tt.addEventListener(TimerEvent.TIMER, checkConnection);
tt.start();
//listen for interaction
stageRef.addEventListener(TouchEvent.TOUCH_BEGIN, refreshTimer);
stageRef.addEventListener(MouseEvent.CLICK, refreshTimer);
}
private function refreshTimer(e:MouseEvent):void {
//some interaction on stage, restart timer
tt.reset();
tt.start();
}
private function checkConnection(e:TimerEvent):void {
//no interaction, stop the timer
tt.stop();
//check for internet connection
var req:URLRequest = new URLRequest("www.yourWebserviceDomain.com/aTestFile.txt");
ldr = new URLLoader(req);
ldr.addEventListener(IOErrorEvent.IO_ERROR, onIoErrorEvent);
ldr.addEventListener(ProgressEvent.PROGRESS, onLoaderActivity);
ldr.addEventListener(Event.COMPLETE, onLoaderActivity);
}
private function onIoErrorEvent(e:IOErrorEvent):void {
//The remote server is not working, maybe it fixes itself in a while...
tt.reset();
tt.start();
//remove listeners
checkConnectionDone();
}
private function onLoaderActivity(e:ProgressEvent):void {
//The webservice is up and running, lets refresh...
if (ExternalInterface.available) ExternalInterface.call("document.location.reload");
//and reset timer
tt.reset();
tt.start();
//remove listeners
checkConnectionDone();
}
private function checkConnectionDone():void {
if (ldr.bytesLoaded < ldr.bytesTotal) ldr.close();
ldr.removeEventListener(IOErrorEvent.IO_ERROR, onIoErrorEvent);
ldr.removeEventListener(ProgressEvent.PROGRESS, onLoaderActivity);
ldr.removeEventListener(Event.COMPLETE, onLoaderActivity);
ldr = null;
}
}
}