Getting an error in FileReference.save method

962 Views Asked by At

I am currently working in Flex 3.0 I am getting an error(screen shot is given below). I am using Flash Player Version 10.0

Currently I am calling the HTTPService and in the resultHandler of that HTTPService i am getting an error in method filereference.save() . because this method is called only when the MouseEvent or Keyboard event is occured.

Is there any solution to overcome this situation or in other words calling the filereference.save method in ResultHandler.

enter image description here

3

There are 3 best solutions below

2
On BEST ANSWER

You cannot. You need a click button of the user to get it done. Dispatching a MouseEvent is useless. Romi approach coud help you. But you need for security reasons to made it for a button click.

What I did.. was in the result retrive the file location and open it like an html page. Then you can download it. I see no other solution than forcing the user to click a button like Romi said.

var u:URLRequest = new URLRequest(event.result); 
navigateToURL(u, "_blank");
0
On

An alternative solution might be to send the file to the server, then have the server send it back to the client which should trigger the browser's save/open dialog box. But if the file is created by flex then this is not ideal bandwidth-wise.

0
On

The reason for this is that you are no longer allowed to automatically trigger the display of file saving popups, except in the event of the user actually requesting this, via an event generated by the user. Here is some more info on the subject: http://www.bogdanmanate.com/2010/05/12/flex-error-2176-when-using-filereference/

I got around this problem using the solution described in the post, namely by using a Yes/No alert, to indicate to the user that the file has finished loading and it is ready for download and finally by asking him to confirm that he wants to save it locally. You might consider thins user-unfriendly, but it's really about security. And once you know how to trigger the event, you can figure out ways of bypassing this UI issue.

Have a great day!