[also posted this on Actionscript 3 forum but I’m having trouble getting a response]
I’m using the following Actionscript 3 code to generate a new text file (myFile.txt) with some text in it:
Actionscript:
var req:URLRequest = new URLRequest("http://localhost/workDir/save.php");
req.method = URLRequestMethod.POST;
var postVars:URLVariables = new URLVariables();
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
submitBtn.addEventListener(MouseEvent.CLICK, submitData);
function submitData(event:MouseEvent):void {
postVars.fName = "myFile";
postVars.fFormat = ".txt";
postVars.fText = "Type some text here.";
req.data = postVars;
loader.addEventListener(Event.COMPLETE, loaderFinished);
loader.load(req);
}
function loaderFinished(evt:Event):void {
trace("Submit complete, data: " + loader.data);
output_txt.text = "Submit complete";
}
Here’s save.php:
<?php
$fileName = $_POST['fName'].$_POST['fFormat'];
$fileText = $_POST['fText'];
$file = fopen($fileName, "a+");
fwrite($file, $fileText);
fclose($file);
echo "$resu1=Created ".$fileName;
echo "$resu2=Created ".$fileText;
?>
When I run the standalone swf, and when I publish as a projector (.exe), everything works fine. When I publish and open the HTML with the swf embedded, it doesn’t work – no file, no “Output complete” in the output_txt field.
What am I missing?