Flex

Strange Hack For Downloading With a FileReference

By Niall Kader1 min read

This article is from the original REM DEV blog (2008–2010). Some of the technologies it covers (Flex, Flash, AIR, JavaFX 1.x) have since been retired.

My file download wasn't working and I sometimes got an I/O Error - 2038. I dug around the internet and found this very strange hack.  You have to create a nested function in the same scope as the call to the download() method of the FileReference. It makes no sense to me, but it works!  I also found it helpful to declare your FileReference as a class member (with global scope) rather than a local variable inside a function.

private var frDownload:FileReference;

private function downloadSomeFile():void
   
var url:URLRequest = new URLRequest(someURL)
    frDownload = new FileReference();
  
//you coud add your even listeners here

   var thisIsCrazy:Function = function():void{};//CRAZY!!!!!!!!
    frDownload.download(url);
}