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.
OK… is there another explanation on how to do this. I just didn’t get it.
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
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. 
ThaJock : did you get it ?
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.
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
[ 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”;
if(!fileRef.download(url, “FlashPlatform.pdf”)) {
trace(“dialog box failed to open.”);
}
[ code end ]
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”;
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.
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”;
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]
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?