【问题标题】:AS3 how to can I get the URLRequest to repeat the action at set intervalsAS3 如何让 URLRequest 以设定的时间间隔重复操作
【发布时间】:2013-01-15 18:14:50
【问题描述】:

我正在运行下面的 AS3 以将“.txt”文件加载到内置于 Flash CS5 中的 Adob​​e Air 桌面应用程序留言板。我设置了一个计时器来运行并重复该过程,基本上是再次运行代码并触发 NotificationType.Critical。即使没有加载新文件。

如何使 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 的新手

【问题讨论】:

  • 文件在线还是本地文件?可以使用File.modificationDate检查本地文件上一次修改本地文件的时间。
  • 查看我的编辑版本以供程序使用。

标签: actionscript-3 air flash-cs5


【解决方案1】:
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);
}

【讨论】:

  • 我的链接有错误,抱歉,正在工作!!如果它稍后会触发通知,我现在就让你
  • 好吧,我又遇到了一个问题,哈哈,我会将所有代码发布到一个新问题上。每次查找新文件时都会使 NotificationType.Crytical 关闭。
猜你喜欢
  • 1970-01-01
  • 2015-11-13
  • 2021-12-21
  • 2014-02-15
  • 2011-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多