PDA

View Full Version : Problem with a swf refusing to load updated XML data


avi999912
02-13-2009, 04:55 PM
Problem with a swf refusing to load updated XML data....
i'm updating the xml File from the website administration page.
the data is written into the xml file.... later on the data is gethred from the xml file by the .swf file. my problem is that the .swf file isn't updating the text that he holds in him, although the information has changed in the xml file. how can i fix this problem?

atomic
02-13-2009, 05:03 PM
When and how are you reading in the .xml data into the .swf?

avi999912
02-13-2009, 07:00 PM
this is my code:

var theText:TextField = new TextField();
var theText2:TextField = new TextField();
var theFormat:TextFormat = new TextFormat();
theFormat.size = 20;

var xmlLoader:URLLoader = new URLLoader();
var menuURL:URLRequest = new URLRequest("menu.xml");
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
xmlLoader.load(menuURL);
var menuXML:XML = new XML();
menuXML.ignoreWhitespace=true;

function xmlLoaded(evt:Event):void{
menuXML = XML(xmlLoader.data);
theText.text = " " + "coctails\n\n"
for(var item:String in menuXML.Item){
if (menuXML.Item[item].CategoryName == "coctails"){
'var arrayString[] = menuXML.Item[item].Price.split(".")'
theText.text = theText.text + "\n" + menuXML.Item[item].Name + " " + menuXML.Item[item].Price + " ש\"ח"
'theText.textColor = 0xFFFFFF'
theText.setTextFormat(theFormat);
}
}

atomic
02-13-2009, 07:14 PM
This AS3.0 code, no?

endergrl
02-13-2009, 07:36 PM
one thing you can try is tracing out menuXML after the xml file has loaded to see if it is tracing the new xml file rather than the old one. also verify the xml file to make sure the updates are there. and other than that clearing your cache or forcing the web browser to not cache it.

mkeeganwatkins
02-13-2009, 08:12 PM
this can be solved by specifying a unique URL for the XML file, by appending a random number

- say your xml file is called "myConfig.xml"
- store it in a variable and append a random number to the end of the file name
- since the extra query is random, the file you are requesting will be different each time, i.e. "myConfiig.xml?14" -> "myConfig.xml?56" -> "myConfig.xml?12"

here is a sample:

var baseFile:String = "myConfig.xml?";
var randomQuery:Number = Math.floor(Math.random() * 100);
var uniquePath:String = baseFile + randomQuery;
trace(path);

then you would just use the unique version in a URLLoader :

var request:URLRequest = new URLRequest(uniquePath);
var loader:URLLoader = new URLLoader(request);

in this way, you are technically requesting a different resource every time, although it will continue to pull the XML file. If you want more randomness, change the number generator line to

var randomQuery:Number = Math.floor(Math.random() * 1000);

which will add three digits instead of two.

hope that helps!

avi999912
02-14-2009, 07:18 AM
this causing the following error:
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///D|/menu.xml81
at scrollbar_fla::MainTimeline/scrollbar_fla::frame1()

the updates are there.... the .swf file is not updating himself.

mkeeganwatkins
02-14-2009, 03:42 PM
this causing the following error:
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///D|/menu.xml81
at scrollbar_fla::MainTimeline/scrollbar_fla::frame1()

make sure to add the question mark to the end of the base file name, i.e "myXML?" BEFORE you add the random number. In your example that I've quoted here, you would need to make sure it was "file:///D|menu.xml?81"

Without that question mark, you are requesting a file named "menu.xml81", but with the question mark you are requesting a file named "menu.xml" with a query value of "81". Hope that makes sense.

atomic
02-14-2009, 04:18 PM
Also, this won't work when testing in the Flash application itself, only testing through an .html, and possibly only when tested online, not locally.

mkeeganwatkins
02-15-2009, 02:56 AM
Also, this won't work when testing in the Flash application itself, only testing through an .html, and possibly only when tested online, not locally.

@atomic => you're absolutely right. for testing locally or within the Flash authoring environment, the best solution would probably be to save a copy of your XML with a slightly different name, i.e "items_1.xml" and then update the reference in your URLRequest.

snickelfritz
02-15-2009, 07:15 AM
There's a class called "cachebuster (http://evolve.reintroducing.com/2007/11/08/as3/as3-cachebuster/)" that seems to work pretty well for this.