问题
So, I have a flash application that handles several client profiles for a company. Whenever a new client profile is created, it saves a new XML file localy. My problem is that instead of doing a "silent" file creation, a window pops up just like doing a "Save As" as to confirm that the file is being saved on disk and which name should it be.
Is there a way to do a file save within flash without it calling out that window? If so, would it be possible to link me to an example of it?
Here is an example of my code:
var xmltosave:XML = new XML ( "<?xml version="1.0" encoding="utf-8"?><cliente><id>"+idfield.text+"</id><nome>"+nomefield.text+"</nome><tipo>"+tipofield.text+"</tipo><empresa></empresa><email>"+emailfield.text+"</email><contacto>"+contacto1field.text+"</contacto><contacto2>"+contacto2field.text+"</contacto2><profissao></profissao><datainscricao>"+datafield.text+"</datainscricao><dataalteracao></dataalteracao><notas></notas><notas2></notas2><notas3></notas3></cliente>");
var file:FileReference = new FileReference;
var filepath:String = new String(idfield.text + ".xml");
file.save( xmltosave, filepath );
Also, I know that the xmltosave is very long, is it possible to do line breaks in AS3 code?
Thank you. Marco Roberto.
NOTE: I know that I should use a php script to manage files, but unless that php is able to run locally without any server installs, like XAMPP, im not interested in using it. This is a small project and I just need to handle XML files. Unless its absolutely impossible to do it without PHP scripts, I would prefer a AS3 solution.
回答1:
since you're building a desktop application you can use flash.filesystem.File, which is part of the AIR SDK, to save files as a background process.
来源:https://stackoverflow.com/questions/7379649/flash-actionscript-3-saving-a-xml-file-locally-has-a-save-as-window-how-can-i