loading external xml file
From the 'Learning Actionscript 3' book I'm trying out reading/writing to an xml file.
Actionscript:
var txtFld:TextField = new TextField();
txtFld.width = 500;
txtFld.height = 350;
txtFld.multiline = txtFld.wordWrap = true;
addChild(txtFld);
var str:String = "<?xml version='1.0' encoding='utf-8'?>";
str += "<value>Sent from ActionScript</value>";
var xmlToSend:XML = new XML(str);
var req:URLRequest = new URLRequest("save_xml.php");
req.data = xmlToSend;
req.contentType = "text/xml";
req.method = URLRequestMethod.POST;
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(IOErrorEvent.IO_ERROR,
onIOError, false, 0, true);
urlLoader.addEventListener(Event.COMPLETE,
onComplete, false, 0, true);
urlLoader.load(req);
function onIOError(evt:IOErrorEvent):void {
txtFld.text = "XML load error.\n" + evt.text;
}
function onComplete(evt:Event):void {
try {
urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
urlLoader.removeEventListener(Event.COMPLETE, onComplete);
var loadedXML:XML = new XML(evt.target.data);
txtFld.text = loadedXML.stuff;
} catch (err:Error) {
txtFld.text = "XML parse error:\n" + err.message;
}
}
PHP:
<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){
$data = xmldoc($GLOBALS["HTTP_RAW_POST_DATA"]);
$file = fopen("data.txt","wb");
fwrite($file, $data);
fclose($file);
if (!$file) {
echo("<stuff>Server unable to create file.</stuff>");
} else {
echo("<stuff>File saved.</stuff>");
}
}
?>
I'm using MAMP to test it, servers are running and both the flash file and the php script file are in the htdocs location. So I'm trying out http://localhost:8888/send_load_xml.swf and in the same location is save_xml.php and data.txt.
When I run the swf however I always get an 'XML Load Error #2032'. I've checked the name of the php file and the txt file and they are correct. Why am I getting this error?
