actionscript-3airflash-cs5

AS3 how to can I get the URLRequest to repeat the action at set intervals


I am running the AS3 below to load a ".txt" file to an Adobe Air desktop app message board built in Flash CS5. I have a timer set to run and repeat the process, basically to run back through the code again and it is firing off the NotificationType.Critical. even though there isn't a new file loaded.

How can I make it so the URLRequest repeats, let say every 120000 milliseconds to look for new file? If file is new load the file and notify user, if file isn't new just ignore?

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
    }
}

thanks new to AS3


Solution

  • 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);
    }