title: Flex's FileReference.save() can only be called in a user event handler -- how can I get around this?
body: <p>I need to call FileReference.save() after a web service call has completed, but this method has a restriction: "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." (from the documentation <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html?allClasses=1#save%28%29" rel="nofollow noreferrer">here</a>)</p>
  
  <p>This restriction is a bit vague.  Does it mean that I can only call the FileReference.save() method from within an event handler function that is registered as a listener for certain types of user events?  If so then exactly which user events are valid?  (Perhaps there's an event that will never be dispatched by user interaction with my application and I could register an event handler function for that event type and make the save() call from within that function?)</p>
  
  <p>My difficulty is that I can't safely call the FileReference.save() method until my web service returns with the data that will be used as the argument of the FileReference.save() method call, so the event that triggers the FileReference.save() call is actually a ResultEvent rather than a user event, and I'm leery of dispatching a new (faux) user event type in order to be able to trigger the FileReference.save() call unless it's definitely a user event that would never be dispatched as a result of actual user interaction with my application.</p>
  
  <p>In a nutshell what I'm doing now is this: I have a function that is registered as a handler for a button click.  In this function I make my web service call to fetch data from the server.  I also have a result handler function which gets invoked when the web service call completes, and it's in here that I want to call the FileReference.save() method since it's at this point that I know that the data is ready to be saved to a file.  But the aforementioned restriction is blocking me from doing this -- I get an error:</p>
  
  <pre><code>Error #2176: Certain actions, such as those that display a pop-up window, 
  may only be invoked upon user interaction, for example by a mouse click 
  or button press.
  </code></pre>
  
  <p>I've tried many things to get around this such as creating a second mouse click event handler function with the FileReference.save() call within and calling it after a timeout interval (to give the web service time to complete), but I keep running into the same error -- maybe that approach doesn't work since the second function isn't registered as an event listener for the event type used as its argument.</p>
  
  <p>I'm new to Flex development so perhaps I'm just not thinking about this in the right way.  If anyone can suggest another approach I'd really appreciate it.  Thanks in advance for your comments or suggestions.</p>
  
  <p>--James</p>