Refresh XML Every 10 Seconds

  • saveth
  • Born
  • Born
  • No Avatar
  • Joined: Aug 12, 2006
  • Posts: 2
  • Status: Offline

Post August 13th, 2006, 2:23 pm

I'm looking for a way to refresh a xml every 10 seconds or so. I tried rapping the complete loadxml function in another function and then doing a setInterval on it but so far I've been unsuccessful.

Any help would be appreciated.

Code: [ Select ]
function loadXML(loaded) {
    if (loaded) {
        xmlNode = this.firstChild;
        songTitle = xmlNode.childNodes[8].childNodes[0];
        songTitle = songTitle_txt.text.toUpperCase();
        songTitle = songTitle_txt.text.searchReplace(" - ", ": ");
        songTitle_txt.autoSize = true;
        buy_mc._x = songTitle_txt._x+songTitle_txt._width+5;
        buy_mc._y = songTitle_txt._y;
    } else {
        content = "file not loaded!";
    }
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("http://www.crylounge.com/shoutcast.php");

String.prototype.searchReplace = function(str, rep, chr) {
    var t = (chr<0) ? this.substr(chr) : this.substr(0, chr);
    var s = str.length;
    var r = rep.length;
    var p = t.indexOf(str);
    while (p != -1) {
        t = t.substr(0, p)+rep+t.substr(p+s);
        p = t.indexOf(str, p+r);
    }
    return (chr) ? (chr<0) ? this.substr(0, this.length+chr)+t : t+this.substr(chr) : t;
};
  1. function loadXML(loaded) {
  2.     if (loaded) {
  3.         xmlNode = this.firstChild;
  4.         songTitle = xmlNode.childNodes[8].childNodes[0];
  5.         songTitle = songTitle_txt.text.toUpperCase();
  6.         songTitle = songTitle_txt.text.searchReplace(" - ", ": ");
  7.         songTitle_txt.autoSize = true;
  8.         buy_mc._x = songTitle_txt._x+songTitle_txt._width+5;
  9.         buy_mc._y = songTitle_txt._y;
  10.     } else {
  11.         content = "file not loaded!";
  12.     }
  13. }
  14. xmlData = new XML();
  15. xmlData.ignoreWhite = true;
  16. xmlData.onLoad = loadXML;
  17. xmlData.load("http://www.crylounge.com/shoutcast.php");
  18. String.prototype.searchReplace = function(str, rep, chr) {
  19.     var t = (chr<0) ? this.substr(chr) : this.substr(0, chr);
  20.     var s = str.length;
  21.     var r = rep.length;
  22.     var p = t.indexOf(str);
  23.     while (p != -1) {
  24.         t = t.substr(0, p)+rep+t.substr(p+s);
  25.         p = t.indexOf(str, p+r);
  26.     }
  27.     return (chr) ? (chr<0) ? this.substr(0, this.length+chr)+t : t+this.substr(chr) : t;
  28. };


Thanks,
Saveth
[/code]
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post August 13th, 2006, 2:23 pm

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1254
  • Loc: Ro
  • Status: Offline

Post August 14th, 2006, 5:03 am

how exactly you used the setInterval function?

all you need to do is:
Code: [ Select ]
myLoadInteval = setInterval(LoadFile, 10000);

function LoadFile()
{
  xmlData.load("http://www.crylounge.com/shoutcast.php");
}
  1. myLoadInteval = setInterval(LoadFile, 10000);
  2. function LoadFile()
  3. {
  4.   xmlData.load("http://www.crylounge.com/shoutcast.php");
  5. }

The rest of your code remains the same.

if you use your page on a browser, there can be a problem with the local cache.
So probably your code works, but the file is read each time from the local cache ... so it doesnt change.
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 75 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.