Reputation: 433
So I have these two scripts that comunicate with each other to create a xml file online. The way I have it now, AS3 swf sends a few variables to a php script to write. I got the creating part, but for some reason, the php does not write a xml file. I tried changing the variable to a simple "foobar" string, and it works. But If I do a:
var temp:XML = new XML(<test></test>);
It doesen't write it. So what's up, is this normal?
AS3
function SaveXml(inputxml:XML){
var temp:XML = <teste></teste>;
var variables:URLVariables = new URLVariables();
variables.xmlfile = temp;
variables.folder = TestProperties.Username;
var request:URLRequest = new URLRequest("savexml.php");
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
try{
loader.load(request);
}
catch (error:Error) {
trace("Unable to load URL");
}
loader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(e:Event)
{
//something when complete;
}
}
PHP
<?php
date_default_timezone_set('GMT');
$xmlfile = $_POST["xmlfile"];
$folder = $_POST["folder"];
$filename = date('ymdhis').".xml";
if(! file_exists("./user/".$folder."/")){
mkdir("./user/".$folder."/", 0777);
}
$handle = fopen("user/".$folder."/".$filename, 'w+');
fwrite($handle, $xmlfile );
fclose($handle);
echo "result=success";
?>
Upvotes: 0
Views: 713
Reputation: 754
You can't create a xml in flash like you did.
var temp:XML = <teste></teste>;
Because there is no object like in your file. What you need to do is provide a string as a parameter when instantiating the XML object.
So, you should do something like below,
var temp:XML = new XML("<teste></teste>");
Now your code can send xml to php.
Upvotes: 2