/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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(); }