There is no save() method in FileReference Class of Flex

729 views Asked by At

i'm trying to export the content of DataGrid into PDF

var bytes:ByteArray = myPDF.save(Method.LOCAL);
var f:FileReference = new FileReference();
f.save(bytes,"TestAttachment.pdf"); 
/* Call to a possibly undefined method save through a reference with static type flash.net:FileReference. */

i'm using AlivePDF version 0.1.4.9 and flex builder 3 for building a simple Flex Application

3

There are 3 answers

0
Yasuyuki  Uno On

I think this problem is caused by build settings.

In Flex Builder > Project > Properties > Flex Compiler, set the minimum Flash Player version to over 10.0.0.
After that, you can use FileReference.save() method.

Maybe your setting was 9.x.x

0
Nitesh Jain On

updated the flex SDK to 3.6A and Flex compiler version to 10.1.0, Thanks @(Yasuyuki Uno) and FileReference.Save worked

var f:FileReference = new FileReference();
f.save(bytes,"TestAttachment.pdf");
0
Philarmon On

A FileReference is just a reference to a file, you are looking for a FileStream. Assuming the ByteArray is already the PDF content:

var bytes:ByteArray = myPDF.save(Method.LOCAL);
var file:File = File.desktopDirectory.resolvePath("myPDF.pdf");
var fileStream:FileStream = new FileStream();

fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(bytes);
fileStream.close();

For directory locations on different devices, check this out