AS3/Flex FileReference download problem - solved
If the file reference object is created as a function local variable the download save box appears but the file is never saved.
The solution is documented on the Adobe knowledgbase: FileReference.download() in SWF file fails and I found it via this thread.
The long and short of it is:
Problem code (note the fileRef is inside the function):
var fileRef:FileReference = new FileReference();
fileRef.download(new URLRequest("myFile.txt"), "myFile.txt");
}
function downloadFile():void {
fileRef.download(new URLRequest("myFile.txt"), "myFile.txt");
}
Hope it saves someone some time - or increases the chances of the technote being found quickly via google.
Cheers, Mark





I had the same problem and ended up implementing the full example provided in the Flex 3 docs. The weird thing was it seemed to work and the stopped functioning a week later, but it could have been my imagination. At least now I know it wasn't me - exactly :-)
Richard
Thanks to you and Google. Life is easier.:)
Very useful link, thank you!
gracias amigo
Thx :)
i'm ready to cry. I thought I must be incredibly dumb. Thank you! Thank you! Thank you!
Refactoring broke my stuff!!
Many Thanks!
Kiitos
please check this example under the below link:
http://www.acoukess.info/bernard/download-in-AS3.z...
please check this example under the below link:
http://www.acoukess.info/bernard/download-in-AS3.z...
However it is totally wierd, because server is returning
206 Partial Content
Brr. Thanx, anyway.
function downloadFile():void {
fileRef.download(new URLRequest("myFile.txt"), "myFile.txt");
}
Solved partially.
If in windows "Hide known file extensions" is checked.
the save as popup wiill come with filename as "myFile".
if I download it it will work fine and file be with ".txt" extension automatically.
But
If I rename "myFile" to "myFile11" it will be downloaded
but become unuseable.
Have any workaround for this.
I was wondering if its possible to download from an XML list. I tried referencing from xml file's url node, but it seems it won't detect, I kept getting an error saying I can only put http or https address/protocol.
Thanks,
Reina Lyn Ben