The code flow is as follows:
user clicks 'download details' button on the page -> on button click handler a call to a RPC method is made using s:CallResponder -> RPC method generates and returns a URL from where to download the file -> the success event handler of the CallResponder gets the url where FileRefrence.download() is used to download the file but throws following error:-
Error: 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. at flash.net::FileReference/download()
Code is follows:
<fx:Script>
<![CDATA[
import mx.rpc.CallResponder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
protected function downloadButtonClickHandler(event:MouseEvent):void
{
var web_service:IWeb_service = Web_service.getInstance();
getDetails.token = web_service.getURLDetails();
}
public function onGetDetailsResult(event:ResultEvent):void
{
var response:URLResponse = event.result as URLResponse;
if(response != null && response.url != null)
{
var request:URLRequest = new URLRequest(response.url);
fileReference.download(request, "test.html");
}
}
public function onGetDetailsFault(event:FaultEvent):void
{
Alert.show("Error in downloading details");
}
]]>
</fx:Script>
<fx:Declarations>
<net:FileReference id="fileReference" />
<s:CallResponder id="getDetails" result="onGetDetailsResult(event)" fault="onGetDetailsFault(event)"/>
</fx:Declarations>
<s:HGroup width="100%" height="100%">
<s:Button label="Download Details" id="downloadButton"
click="downloadButtonClickHandler(event)" />
</s:HGroup>
Is there any other way of achieving this as File FileReference needs a user interaction which is not happening int his case?