Return to Snippet

Revision: 39768
at January 20, 2011 20:02 by brianleanza


Initial Code
private var fileToSave:File = File.documentsDirectory;

// click handler
protected function buttonExportToCSV_clickHandler(event:MouseEvent):void
{
   fileToSave.addEventListener(Event.SELECT, fileToSave_selectedHandler);
   fileToSave.browseForSave("Save .CSV");
}

protected function fileToSave_selectedHandler(event:Event):void
{
   var nativePath:String;
   if( fileToSave.extension == null ) {
     nativePath = fileToSave.nativePath + ".csv";
   }
   else {
     nativePath = fileToSave.nativePath.substr(0, fileToSave.nativePath.lastIndexOf(fileToSave.extension)) + ".csv";
   }

   var file:File = new File(nativePath);
   if( file.exists ) {
      Alert.show("There already exists a .csv file of that name", "Exporting Aborted");
   }

   var stream:FileStream = new FileStream();
   stream.open(file.FileMode.WRITE);
   stream.writeUTFBytes(value); // value being the clipboard content
   stream.close();
}

Initial URL


Initial Description


Initial Title
Save String To File

Initial Tags


Initial Language
ActionScript 3