我正在运行下面的AS3,将“.txt”文件加载到Flash CS5内置的Adobe Air桌面应用留言板。我有一个计时器设置为运行并重复该过程,基本上是再次运行代码并且它触发了NotificationType.Crtitical。即使没有加载新文件。
我怎样才能使URLRequest重复,假设每隔120000毫秒寻找新文件?如果文件是新加载文件并通知用户,如果文件不是新的只是忽略?
var loader:URLLoader = new URLLoader(new URLRequest("https://my_text_file.txt"));
loader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void {
var loadedText:URLLoader = URLLoader(event.target);
if(myText_txt.htmlText!=loadedText.data){
myText_txt.htmlText = loadedText.data;
mainWindow.notifyUser(NotificationType.CRITICAL)
}else {
//do nothing
}
}
感谢AS3
答案 0 :(得分:0)
var myInterval:uint = setInterval (loadUrl, 120000);
var loader:URLLoader = new URLLoader(new URLRequest("https://my_text_file.txt"));
loader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void {
var loadedText:URLLoader = URLLoader(event.target);
if(myText_txt.htmlText!=loadedText.data){
myText_txt.htmlText = loadedText.data;
mainWindow.notifyUser(NotificationType.CRITICAL)
}else {
//do nothing
}
}
function loadUrl():void {
loader = new URLLoader(new URLRequest("https://my_text_file.txt"));
loader.addEventListener(Event.COMPLETE, completeHandler);
}