# File Download

**URL:** <https://forum.kirupa.com/t/file-download/290650>\
**Category:** flash\
**Created:** [June 17, 2009, 4:53pm UTC](https://forum.kirupa.com/t/file-download/290650 "2009-06-17T16:53:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dygfloyd](https://avatars.discourse-cdn.com/v4/letter/d/9fc29f/32.png) [@dygfloyd](https://forum.kirupa.com/u/dygfloyd)\
**Post date:** [June 17, 2009, 4:53pm UTC](https://forum.kirupa.com/t/file-download/290650/1 "2009-06-17T16:53:23Z")

</div>

Hey everyone,

Got a very simple problem. Trying to download a file in AS3. Code looks pretty simple but I must be doing something wrong. It opens the file reference box, all the data looks good but the file is not saved. Anyone got any ideas? This is a simple standalone file so I just put it in frame 1 of the timeline. I’m pulling in my data from FlashVars but I know all of that works.

```auto

var fileRef:FileReference = new FileReference();
var DownloadFile:String = Object(LoaderInfo(this.loaderInfo).parameters).DownloadFile;
var LinkText:String = Object(LoaderInfo(this.loaderInfo).parameters).LinkText;
var Filename:String;
var DLReq:URLRequest = new URLRequest(DownloadFile);

// Trims a fully qualified URL to just the filename
if (DownloadFile.lastIndexOf("/") != -1) {
    Filename = DownloadFile.substr(DownloadFile.lastIndexOf("/")+1);
} else if (DownloadFile.lastIndexOf("\\") != -1) {
    Filename = DownloadFile.substr(DownloadFile.lastIndexOf("\\")+1);
} else {
    Filename = DownloadFile;
}

btn.buttonMode = true;
btn.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void
{
    fileRef.download(DLReq, Filename);
}

```

Thanks for your help!
