Skip to main content
Inspiring
November 16, 2010
Answered

Download MP3 instead of open in WMP or browser?

  • November 16, 2010
  • 2 replies
  • 3040 views

Hello - here's the simple code I'm working with:

download_btn.addEventListener(MouseEvent.CLICK, onDownload);
function onDownload(e:MouseEvent):void {
    var dl_request:URLRequest = new URLRequest(current_url);
    try {
      navigateToURL(dl_request, '_blank');
    } catch (e:Error) {
      trace("Error occurred!");
    }
}

Basically, this is a button that (when clicked) is supposed to allow the user to download an MP3 file.  It works as planned except that when the button is clicked, the MP3 just opens up in the browser or in Windows Media Player or whatever default "playing" application the user has.  I want it to work in the same way as when you right-click a link and choose "Save Link As..." so that when they click it they actually will save the MP3 file itself to their computer (so, the "Save" dialog box will pop up when they click the link), instead of the file just opening/playing.

Is this possible without making separate .zip file versions of all the MP3s?  Thanks!

This topic has been closed for replies.
Correct answer markerline

That works for building a right-click menu, but it still plays the file just as it did before (opens up and starts playing in the default media player application).

Damn.


I found a much simpler solution "Downloading files from a Server" on this page:

http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7cf8.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7ce8

the solution is a basic 3-4 line bit of code which you should be able to implement without using classes and packages in a standard FLA file.

2 replies

markerline
Inspiring
November 16, 2010

Here is a similar thread with a similar question as yours:

http://forums.adobe.com/message/192360#192360

markerline
Inspiring
November 16, 2010

Some users have certain features of their browsers activated.  For example, if you have QuickTime installed, whenever you click an mp3 hyperlink (even in standard HTML) then Quicktime will handle the link and play in the browser instead of a dialog box opening to save the file.  I think instructing your users to right-click and "save as" is the most feasible option without tinkering with other file-handling options which might be done in JavaScript.

-markerline

Inspiring
November 16, 2010
I think instructing your users to right-click and "save as" is the most feasible option


And I'd even be fine with doing that.  But Flash's right-click menu doesn't operate the same way as a browser's right-click menu.  Is there a workaround for that?

Here is a similar thread with a similar question as yours:

http://forums.adobe.com/message/192360#192360

I'd actually seen that too when searching, but the site doesn't have PHP installed on it, so that's not an option for me either.

markerline
Inspiring
November 16, 2010

That works for building a right-click menu, but it still plays the file just as it did before (opens up and starts playing in the default media player application).

Damn.


Yeah.  I just figured that out myself.  On my machine it brings up QuickTime Player which itself has a context-menu to "Save As Source..." which allows you to download the file.  But I'm thinking, did you try the import.flash.filesystem.* method?  With FileSystem you can probably access the file itself as if the file were a desktop file directly from the web.  I will look into it also to see if I find something on this.