Flex error #2176 when using FileReference

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" 
				minWidth="955" minHeight="600"
			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");
This entry was posted in Flex and tagged , . Bookmark the permalink.

4 Responses to Flex error #2176 when using FileReference

  1. Anonomyous says:

    Great info. This was exactly what I was looking for.

  2. Irek says:

    Thx man! works perfect!

  3. Voctrals says:

    Thanks a lot. Fix my problem.

  4. KallidaiRavi says:

    Thanks a lot. Was looking something like this for a while. Appreciate your support.

Leave a Reply

Your email address will not be published. Required fields are marked *