dam
dam

Reputation: 33

how to export arraycollection to .xml file to my local machine

How can I export my arraycollection to .xml file and save it on the hard disk? because presently i could be able to convert from arraycollection to xml object but I am unable to save it as .xml file physically. please somebody help me in this.

Thanks in advance!

Upvotes: 0

Views: 430

Answers (1)

Creative Magic
Creative Magic

Reputation: 3151

If you are using Flash Player, your only choice is to use the FileReference class. With it's method save() it's possible to open a native dialog window that allows you to save the file locally.

If you are using Adobe Air, it's possible to use either FileReference class or File class to save the desired data. While FileReference works the same as in Flash Player, the File class has extended methods, it allows to both read and save files by starting a file stream and it does not require user interaction.

Here's are quick snippets for both classes:

FileReference:

var fr:FileReference = new FileReference();
fr.addEventListener(Event.COMPLETE, onComplete);
fr.save(yourData, "filename.extension");

private function onComplete(e:Event):void
{
    // do something when file is saved
}

File:

var f:File = new File(path);
var fileStream:FileStream = new FileStream();
fileStream.open(fileWriter, FileMode.WRITE);
fileStream.writeUTFBytes(xmlData); // you can use writeBytes() for binary data
fileStream.close();

You can find plenty tutorials that explain more about using these classes on the internet if you wish to study more about them.

Upvotes: 2

Related Questions