# Downloadable File

**URL:** <https://forum.kirupa.com/t/downloadable-file/265614>\
**Category:** flash\
**Created:** [July 10, 2008, 6:19pm UTC](https://forum.kirupa.com/t/downloadable-file/265614 "2008-07-10T18:19:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThaJock](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@ThaJock](https://forum.kirupa.com/u/ThaJock)\
**Post date:** [July 10, 2008, 6:19pm UTC](https://forum.kirupa.com/t/downloadable-file/265614/1 "2008-07-10T18:19:56Z")

</div>

How do I create a download button for a song I have on my server. I just want a download window to pop out without the user having to leave the page.

I tried this in the actions layer frame but it took me to the page only to listen to the song.

btn\_song.onRelease = function () {  
getURL(“address”);  
}

If someone can help me out I would greatly appreciate it.

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [July 10, 2008, 6:25pm UTC](https://forum.kirupa.com/t/downloadable-file/265614/2 "2008-07-10T18:25:52Z")

</div>

[http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs\_Parts&file=00002210.html](http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002210.html)

help yourself 🙂

---

<div class="post-metadata">

**Author:** ![ThaJock](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@ThaJock](https://forum.kirupa.com/u/ThaJock)\
**Post date:** [July 10, 2008, 7:26pm UTC](https://forum.kirupa.com/t/downloadable-file/265614/3 "2008-07-10T19:26:05Z")

</div>

OK… is there another explanation on how to do this. I just didn’t get it.

---

<div class="post-metadata">

**Author:** ![project107](https://avatars.discourse-cdn.com/v4/letter/p/eada6e/32.png) [@project107](https://forum.kirupa.com/u/project107)\
**Post date:** [July 10, 2008, 7:52pm UTC](https://forum.kirupa.com/t/downloadable-file/265614/4 "2008-07-10T19:52:35Z")

</div>

I think there are 2 ways to do it. The first way, given to you by sparkdemon, is through Flash’s filereference and the cool thing about it, is that you can monitor the download (show a progress bar, etc). The other way, is to pass it through a

```auto
getURL("myfile.pdf", "_blank");

```

piece of code.

I actually didn’t know much about that fileref thing, and now that I’ve read it, it could be really useful. Cheers. 🍺

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [July 10, 2008, 10:05pm UTC](https://forum.kirupa.com/t/downloadable-file/265614/5 "2008-07-10T22:05:54Z")

</div>

ThaJock : did you get it ?

---

<div class="post-metadata">

**Author:** ![ThaJock](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@ThaJock](https://forum.kirupa.com/u/ThaJock)\
**Post date:** [July 10, 2008, 11:30pm UTC](https://forum.kirupa.com/t/downloadable-file/265614/6 "2008-07-10T23:30:24Z")

</div>

Thanks for the replies, guys.  
Good to see ya Project107. I tried the getURL function but what it does is play the song in a quicktime player  
What I wanted was for the download box to appear for the user to save it to his/her HD.

Ok so Sparkdemon,  
Is there any way you can give me an example on how this code might look with a little description of the code?  
Thanks again.

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [July 11, 2008, 5:47am UTC](https://forum.kirupa.com/t/downloadable-file/265614/7 "2008-07-11T05:47:33Z")

</div>

For a start, just copy paste this code in flash editor and run…i

change the url variable to a valid file url instead of this

> **[platform\_overview.pdf](https://www.adobe.com/platform/whitepapers/platform_overview.pdf)**
>
> 839.06 KB

  
[code start]

import flash.net.FileReference;

var listener:Object = new Object();

listener.onSelect = function(file:FileReference):Void {  
trace("onSelect: " + file.name);  
}

listener.onCancel = function(file:FileReference):Void {  
trace(“onCancel”);  
}

listener.onOpen = function(file:FileReference):Void {  
trace("onOpen: " + file.name);  
}

listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {  
trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);  
}

listener.onComplete = function(file:FileReference):Void {  
trace("onComplete: " + file.name);  
}

listener.onIOError = function(file:FileReference):Void {  
trace("onIOError: " + file.name);  
}

var fileRef:FileReference = new FileReference();  
fileRef.addListener(listener);  
var url:String = “[http://www.macromedia.com/platform/whitepapers/platform\_overview.pdf](http://www.macromedia.com/platform/whitepapers/platform_overview.pdf)”;  
if(!fileRef.download(url, “FlashPlatform.pdf”)) {  
trace(“dialog box failed to open.”);  
}

[code end]

---

<div class="post-metadata">

**Author:** ![ThaJock](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@ThaJock](https://forum.kirupa.com/u/ThaJock)\
**Post date:** [July 11, 2008, 7:08am UTC](https://forum.kirupa.com/t/downloadable-file/265614/8 "2008-07-11T07:08:39Z")

</div>

Thanks for your replies, Sparkdemon.

Here’s what I did to get it to work.

Created a button then converted it into a movieclip.  
On frame 1:

stop();

button.onRelease = function () {  
gotoAndStop(2);  
}

And on frame 2

import flash.net.FileReference;  
var listener:Object = new Object();  
listener.onComplete = function(file:FileReference) {  
trace("onComplete : " + file.name);  
}  
var url:String = “[http://www.macromedia.com/platform/whitepapers/platform\_overview.pdf](http://www.macromedia.com/platform/whitepapers/platform_overview.pdf)”;  
var fileRef:FileReference = new FileReference();  
fileRef.addListener(listener);  
fileRef.download(url, “FlashPlatform.pdf”);

//to get it to go back to frame 1

onEnterFrame = function () {  
gotoAndStop(1);  
}

I just changed out the path and the default file name and presto!  
I do get an event handler error but the it works fine.

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [July 11, 2008, 11:08am UTC](https://forum.kirupa.com/t/downloadable-file/265614/9 "2008-07-11T11:08:07Z")

</div>

If you face any problems when getting it to run on actual server do let me know…

[quote=ThaJock;2356719]Thanks for your replies, Sparkdemon.

Here’s what I did to get it to work.

Created a button then converted it into a movieclip.  
On frame 1:

stop();

button.onRelease = function () {  
gotoAndStop(2);  
}

And on frame 2

import flash.net.FileReference;  
var listener:Object = new Object();  
listener.onComplete = function(file:FileReference) {  
trace("onComplete : " + file.name);  
}  
var url:String = “[http://www.macromedia.com/platform/whitepapers/platform\_overview.pdf](http://www.macromedia.com/platform/whitepapers/platform_overview.pdf)”;  
var fileRef:FileReference = new FileReference();  
fileRef.addListener(listener);  
fileRef.download(url, “FlashPlatform.pdf”);

//to get it to go back to frame 1

onEnterFrame = function () {  
gotoAndStop(1);  
}

I just changed out the path and the default file name and presto!  
I do get an event handler error but the it works fine.[/quote]

---

<div class="post-metadata">

**Author:** ![ThaJock](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@ThaJock](https://forum.kirupa.com/u/ThaJock)\
**Post date:** [July 11, 2008, 5:22pm UTC](https://forum.kirupa.com/t/downloadable-file/265614/10 "2008-07-11T17:22:35Z")

</div>

> [@sparkdemon;2356804](#):
>
> If you face any problems when getting it to run on actual server do let me know…

Ok so when I tested the movie it worked just fine but when I uploaded it to the server it doesn’t. The save dialog box will open up and I click save as normal but when I go into the folder where it was saved, the file is not there. It’s just going through the motion but not actually saving the file. Do you have any idea what I may be doing wrong?
