Strange Hack For Downloading With a FileReference

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);
}


RECENT ARTICLES