Problem in downloading file

5.04.2010

POSTED IN Programming | TAGS :

Click a button and download a file in Flex is very simple but Adobe’s official example has a problem which made me spent like 20 mins to find a work around.
This won’t work:

var request:URLRequest = new URLRequest("index.xml");
var fileRef:FileReference = new FileReference();
fileRef.download(request);

But this will work:

var fileRef:FileReference = new FileReference();
function downloadFile():void {   
fileRef.download(new URLRequest("index.xml"));
}
downloadFile();

Currently available for freelance

Let me know if I could be in any help. Feel free to drop me an email: alan(at)hkalan.com or contact me