简体   繁体   中英

AS3: Force Save an Xml File

I want to know if there's a way to force users to save an xml file at a certain location. ie they can't choose where to save the file. I want it to always be saved in the same location as the swf file.


Thanks in advance for your help.

If it runs online you can after you edited the xml convert it to a string. This string can be send to a php or other server side language using a POST or GET request.

Because swf's run client side they can't acces the files on the server. A serverside language like php can acces the files and also write to it.

On the as3 send your xml string to the php script. (check AS3 URL string -> 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 );

On the php side you can use this code (warning this is an example and not secure as everybody can write your myFile.xml now using the url and giving post data named xmldata.

$file = "myFile.xml";
$fileHandle = fopen($file, 'w');
fwrite($fileHandle , $_POST['xmldata']);
fclose($fileHandle );

No you can't.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM