Accessibility

TechNote (Archived)

FileReference.download() in SWF file fails

Issue


A FileReference instance in a Flash Player movie (SWF) file generates a browse or download dialog box, but after choosing the file and submitting, nothing happens. The dialog box and listener events do not fire.

Reason


This can happen if a FileReference instance in ActionScript loses scope and Flash Player 9 deletes it prior to obtaining a response from the user.

Unlike URLLoader instances, FileReference instances do not maintain a hard reference that allow it to remain active in memory after the scope in which it was defined is resolved. As a result, any FileReference instances defined as local variables within function calls will be deleted by the Flash Player at the end of the function call, before the user has a chance to react to the resulting dialog box.

Solution


To allow a FileReference instance to accept a response, it needs to be defined in a persistent scope. This requires that the instance be defined either within the timeline of your movie or as a property of your class and not within the local scope of a function call.

The following example might result in this issue:

 function downloadFile():void { var fileRef:FileReference = new FileReference(); fileRef.download(new URLRequest("myFile.txt"), "myFile.txt"); } 

The following example will work correctly:

 var fileRef:FileReference = new FileReference(); function downloadFile():void { fileRef.download(new URLRequest("myFile.txt"), "myFile.txt"); } 

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:3637d5c3
OS:HP-UX
Linux
Mac OS (All)
Solaris
UNIX
Windows (All)
AIX
Browser:Chrome
Internet Explorer
Netscape
Opera
Safari
Firefox

Products Affected:

flash
flashplayer