0

我想知道是否有办法强制用户将 xml 文件保存在某个位置。即他们不能选择保存文件的位置。我希望它始终保存在与 swf 文件相同的位置。


在此先感谢您的帮助。

4

2 回答 2

0

如果它在线运行,您可以在编辑 xml 后将其转换为字符串。可以使用 POST 或 GET 请求将此字符串发送到 php 或其他服务器端语言。

因为 swf 的运行客户端,他们无法访问服务器上的文件。像 php 这样的服务器端语言可以访问文件并写入文件。

在 as3 上,将您的 xml 字符串发送到 php 脚本。(检查AS3 URL 字符串 -> URLRequest

// url variables all which will appear after ? sign
var url = "www.example.nl/phpfilelocation.php";
var urlVariables : URLVariables = new URLVariables ();
urlVariables.xmldata = myXml.toString();

var request : URLRequest = new URLRequest  ( url );
request.data = urlVariables;
request.method = URLRequestMethod.POST;

var loader : URLLoader = new URLLoader ();
loader.addEventListener( Event.COMPLETE, handleLoaderComplete )
loader.load ( request );

在 php 方面,您可以使用此代码(警告这是一个示例,并不安全,因为现在每个人都可以使用 url 编写您的 myFile.xml 并提供名为 xmldata 的发布数据。

$file = "myFile.xml";
$fileHandle = fopen($file, 'w');
fwrite($fileHandle , $_POST['xmldata']);
fclose($fileHandle );
于 2012-07-27T20:10:53.283 回答
0

不,你不能。

In order to do that, you would need to know a valid path to the user's filesystem. You can't just use C:\mylocation\, because Flash Player will run in others OS's as well, which don't have C:\mylocation\.

If you are using Flash as an internal tool, and not for the web, you have alternatives, like storing the data in the clipboard, and then run a background application that will fetch that clipboard data and save it in a specific path; or simply using AIR.

于 2012-07-29T05:13:26.830 回答