Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save to XML file without user prompt dialog in action script 3?

How can save data into a XML file without user prompt dialog in Action Script 3?

I'm writing an simple application (with adobe flash) that runs on client PC and save user state data in XML file in same directory of app. When i use FileReference it shows a user dialog for saving file. Is there any class to save just XML data directly into XML file?

I think writing just XML (text plane) data couldn't make any security problems? :-?

like image 952
Jalal Avatar asked Nov 27 '25 03:11

Jalal


1 Answers

Im amazed noone has posted this already. Load the xml file into memory using URLLoader, making sure the dataFormat is URLLoaderDataFormat.TEXT, then write it to a file using a filestream.

Working code is posted below

Hope it helps

private function loadConfigFromServer():void{
    var request:URLRequest = new URLRequest(serverConfigXmlLocation);
    configLoader = new URLLoader();

    configLoader.addEventListener(Event.COMPLETE, configLoadCompleteHandler);
            configLoader.addEventListener(IOErrorEvent.IO_ERROR, configLoadIOErrorEventHandler);
    configLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, configLoadSecurityErrorEventHandler);

    configLoader.dataFormat = URLLoaderDataFormat.TEXT;
    configLoader.load(request);

}


 private function configLoadCompleteHandler(event:Event):void{
     configLoader.removeEventListener(Event.COMPLETE, configLoadCompleteHandler);
     configLoader.removeEventListener(IOErrorEvent.IO_ERROR, configLoadIOErrorEventHandler);
     configLoader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,   configLoadSecurityErrorEventHandler);
     trace("config download complete");
     var fs:FileStream = new FileStream();
     try{
         fs.open(new File(localConfigXmlLocation), FileMode.WRITE);
         fs.writeMultiByte(configLoader.data, "unicode");
     }catch(error:IOError){
         trace("IOError saving config xml");
     }catch(error:SecurityError){
         trace("SecurityError saving config xml");
     }finally{
         fs.close();
         parseLocalConfig();
     }
}
like image 193
jln646v Avatar answered Nov 29 '25 19:11

jln646v



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!