我正在尝试制作一个简单的 Flash ActionScript3 程序,通过 PHP 脚本将一些文本保存到文本文件(在我的服务器上)。我希望 Flash 程序能够检测 PHP 脚本是否无法写入。现在我只是想让 Flash 跟踪从 PHP 收到的状态。我的以下代码基于我在网上找到的一些示例。
这是我的 Flash 代码:
import flash.net.*;
import flash.events.*;
var varLoader:URLLoader = new URLLoader;
var varURL:URLRequest = new URLRequest("http://xxxxxxxx/outputTest.php");
var submittedData:URLVariables=new URLVariables();
varURL.data = submittedData;
varURL.method = URLRequestMethod.POST;
submittedData.inputData = "ThisIsTheDataToBeSaved";
submittedData.FileName = "ThisIsTheFileName";
varLoader.addEventListener(Event.COMPLETE, fxnDoneSaving);
varLoader.load(varURL);
function fxnDoneSaving(evt:Event):void{
trace("Done saving.");
trace("Write status: "+String(evt.target.data.WasWritingSuccessful));
}
这是我的PHP代码:
<?php
$receivedFromFlashData = $_POST['inputData'];
$receivedFromFlashFileName = $_POST['FileName'];
$filename = $receivedFromFlashFileName . ".txt";
$myTextFileHandler = fopen($filename,"w");
if($myTextFileHandler)
{$writeInTxtFile = @fwrite($myTextFileHandler,"$receivedFromFlashData");}
fclose($myTextFileHandler);
if ($writeInTxtFile)
{echo "WasWritingSuccessful=success";}
else
{echo "WasWritingSuccessful=failure";}
?>
当 Flash 到达最后的跟踪语句时,我收到以下错误:“ReferenceError: Error #1069: Property WasWritingSuccessful not found on String and there is no default value.”
请帮助我理解我做错了什么?谢谢!