I have difficulty with this since this morning, so I finally decided to ask for your help.. I've tried many solutions but none works as I want. I want to load a XML file (local) and edit it and then save the results in the same file. The loading/reading isn't an issue, it works fine, but to save the file is very hard in as3.
(nb: I have an local serveur, so this isn't the problem)
Here's my best approach of the problem so far (found here):
save.php :
<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){
$xml = $GLOBALS["HTTP_RAW_POST_DATA"];
$file = fopen("http://localhost/cs_texte.xml","wt");
fwrite($file, $xml);
fclose($file);
}
?>
myAs3script.as :
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
// Loading XML -> works fine
xmlLoader.load(new URLRequest("http://localhost/cs_texte.xml"));
//When loading complete
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
trace(xmlData); // Works fine
[.. Do some stuff on xml ..]
var xmlResponse:XML;
var xmlURLReq:URLRequest = new URLRequest("http://localhost/save.php");
xmlURLReq.data = xmlData;
xmlURLReq.contentType = "text/xml";
xmlURLReq.method = URLRequestMethod.POST;
var xmlSendLoad:URLLoader = new URLLoader();
xmlSendLoad.addEventListener(Event.COMPLETE, completeHandler);
xmlSendLoad.load(xmlURLReq);
function completeHandler(evt:Event) {
trace ('Save complete');
}
}
But it's not working, the xml file doesn't change at all, even if I try to empty it..
Any idea why ? (And do you know how to get php error in flash output console ? if there is any..)
Thansk for your help ! (And please be indulgent, this isn't my project initially..)