views:

325

answers:

2

Hey guys,

My Flex client app has got some data from the back end (RemoteObjects, BlazeDS, Spring). Client has got all the data it needs, it now needs to put some information in a CSV format and make it available for download.

Using Flex 3 for this. Any ideas?

Thanks, Sri

A: 

Unfortunately you cannot do it. You have to use FileReference+URLRequest, you cannot create on the fly a file available for download in Flash Player. One workaround is to display your data in a text file and allow the user to do copy/paste. Of course, it works only if you have a small amount of information.

Cornel Creanga
Actually since Flash Player 10 you can create files on the client.
bug-a-lot
+2  A: 

If you are compiling for Flash Player 10 then you can call the FileReference.save() function to save to the local file-system:

http://help.adobe.com/en_US/FlashPlatform//reference/actionscript/3/flash/net/FileReference.html#save()

Just make sure you take note of this section:

In Flash Player, you can only call this method successfully in response to a user event (for example, in an event handler for a mouse click or keypress event). Otherwise, calling this method results in Flash Player throwing an Error exception. This limitation does not apply to AIR content in the application sandbox.

The only other alternative if you can't compile for Flash Player 10 is to send the data to the server and have the user download it from there as a CSV.

You can do this with the FileReference.download() in a simlar manner to save(): http://help.adobe.com/en_US/FlashPlatform//reference/actionscript/3/flash/net/FileReference.html#download()

Sly_cardinal
Thanks for your answer..
Srirangan