Hello. I need help with a file I am working on. I have something that checks a XML file every second, to load in new data.
My question is there a way for flash to check to see if a XML file on a server has been updated or is newer since the last time it loaded it?
Right now I am just using a timer like below, but it makes some tweens I have in the project freeze every second, each time it loads it again.
var checkGrid:Timer = new Timer(1000);
checkGrid.addEventListener(TimerEvent.TIMER, applyGrid);
checkGrid.start();
function applyGrid(event:TimerEvent):void{
var gridXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("grid.xml?new=" + new Date().getTime()));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
gridXML = new XML(e.target.data);
code...
}- United States
- Has been a member for 4-5 years
- Exclusive Author
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Author had a Free File of the Month
You’re creating a new URLLoader and URLRequest every second. Anything “new” is going to be a performance hit, so declare these variables outside of the function and reuse them.
You can use php to check if a file has been modified. This might help:
http://php.net/manual/en/function.filemtime.phpThanks CrackerJack, I got it work.
- Has been a member for 4-5 years
- Author was Featured
- Contributed a Tutorial to a Tuts+ Site
- Netherlands
- Community Moderator
- Microlancer Beta Tester
- Sold between 10 000 and 50 000 dollars
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Exclusive Author
CrackerJack said
You can use php to check if a file has been modified. This might help: http://php.net/manual/en/function.filemtime.php
So that you would have to load only one int instead of an entire XML file? Yeah, suppose that would help – I guess there’s no way around timed loading.. there’s no real way of ‘pushing’ data, is there?
For the sake of reference – how’d you fix it, Grid8?
I know there is a easier way but I got tired of playing around with it.
The project was a game scoreboard, and the timer was a bar that went across the screen, I was checking the xml file every second for new information, and it the made the timer bar and pretty much the entire board choppy and buggy. So instead I just had it check the URL every second, and if it changed then it will load in the new xml file.
I used a different swf that is on the same page, and used that one to check every second if the .xml file was updated, and if it was it would redirect the url
navigateToURL(new URLRequest("#/update/" + loadURL), "_self");