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();
}
}