The flash player 10 has new rules for UIA ( user initiated action ) so when I tried to use the FileReference save method I got the 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. After I made some research I found a very cool article here, but I didn’t found any workaround.
Dispatching a MouseEvent won’t work, because the user must interact with the application by clicking a mouse button or by pressing a keyboard key. I found a way to get rid of this error by displaying a popup and let the user to click a button in order to force the user to interact with the application.
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" creationComplete="creationCompleteHandler(event)"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.CloseEvent; import mx.events.FlexEvent; protected function creationCompleteHandler(event:FlexEvent):void { Alert.show("Now you can save the file!", "Test", Alert.OK|Alert.CANCEL, null, closeHandler); } protected function closeHandler( event:CloseEvent ):void { var fileReference :FileReference; if ( event.detail == Alert.OK ) { fileReference = new FileReference(); fileReference.save("http://www.bogdanmanate.com", "test.txt"); } } ]]> </mx:Script> </mx:Application> |
Great info. This was exactly what I was looking for.
Thx man! works perfect!
Thanks a lot. Fix my problem.
Thanks a lot. Was looking something like this for a while. Appreciate your support.