I have decent PHP and AS3 knowledge, but none regarding connecting the two. I am trying to use AS3 to send data to PHP, and have PHP save them to a XML.
What I don't get is how php is supposed to react to external code. The AS3 script does not start the page, correct? It just sends data to it? Just executing the actionscript side doesn't work nor does loading the php in the browser manually (with apache running correctly, gibberish echo's funcioning) or reloading it after the AS3 sending. The xml stays empty, no return value to trace. All tutorials deal with before and after, assuming that I know how it is that php will react at all to receiving data from AS3. Can someone tell me my missing link?
If it matters, my relevant AS3:
public function xt(e:MouseEvent):void
{
marque = tmarque.text;
prix = tprix.text;
couleur = tcouleur.text;
xmlString = "<?xml version='1.0' encoding='utf-8'?>";
fichier = new XML(xmlString);
fichier = <ordinateurs />;
fichier.marque = marque;
fichier.couleur = couleur;
fichier.PRIX = prix;
var req = new URLRequest("C:/xampplite/htdocs/save_xml.php");
//(have also tried placing the php in same folder)
req.data = fichier;
req.contentType = "text/xml";
req.method = URLRequestMethod.POST;
var xmlSendLoad:URLLoader = new URLLoader();
xmlSendLoad.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
xmlSendLoad.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
xmlSendLoad.load(req);
}
function onComplete(event:Event):void {
try {
var xmlResponse = new XML(event.target.data);
TXTtesticle.text = xmlResponse;
removeEventListener(Event.COMPLETE, onComplete);
removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
} catch (err:TypeError) {
TXTtesticle.text = "An error occured when communicating with server:
" + err.message;
}
trace (xmlResponse);
placeText();
}
and PHP
<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
$xml = $GLOBALS["HTTP_RAW_POST_DATA"];
$file = fopen("data.xml","wb");
fwrite($file, $xml);
fclose($file);
echo($GLOBALS["HTTP_RAW_POST_DATA"]);
}
?>