Flex’s FileReference.save() can only be called in a user event handler — how can I get around this?

Adobe does this as a sort of security measure to ensure users are the ones messing with files rather than potentially harmful code. My understanding is that they enforce this by only allowing handlers of (click?) events that originate from UI components to execute the FileReference methods, so generating your own events programmatically will not work, although I have not tried to verify this. Unfortunately the best resolution I’ve found is to re-work the UI a bit to conform to this constraint. In your particular situation, you could make this a two click process with a button that says something like “Prepare Download”, which changes to “Download File” after the web service is complete. This is less than ideal from a user perspective, but I don’t think there’s much else that can be done unless you can somehow complete your web service call prior to displaying the button that triggers the FileReference.save() call.

Leave a Comment