Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Download MP3 instead of open in WMP or browser?

Contributor ,
Nov 16, 2010 Nov 16, 2010

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!

TOPICS
ActionScript
3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Nov 16, 2010 Nov 16, 2010

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.

Translate
Mentor ,
Nov 16, 2010 Nov 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 16, 2010 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 16, 2010 Nov 16, 2010

I think there's a way to do it with AIR and you can incorporate Flash and AIR together.  I'm looking at a book where it explains how to read and write files.

"The Essential Guide to Flash CS4 with Action Script" published by Friends of Ed (Author: Paul Milbourne, Chris Kaplan, and Michael Oliver).  You might even be able to find a similar approach to the book if you look for the import class:  import.flash.filesystem.*

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 16, 2010 Nov 16, 2010

Also, I think there was a way in the past to alter the menu options for Flash.  For example, you could enable or disable "Print" from the Flash right-click menu.  Perhaps you can add a method to have "Save As" as a menu option for right-click (I just couldn't find it at the moment in the book I have).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 16, 2010 Nov 16, 2010

I think I figured something out here:

http://www.foundation-flash.com/tutorials/customrightclickmenu/

If you look at the section where the tutorial-writer uses "getURL" you can put the complete http location of your mp3 between the quote marks.  I think this tutorial was written in AS 2.0 but it probably will work with some modification in AS 3.0 as well.  If you need the "Save As" functionality to be context sensitive, then build an array of your mp3 addresses and call them by variable in the getURL declaration.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 16, 2010 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 16, 2010 Nov 16, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 16, 2010 Nov 16, 2010

Look at this solution.  The first one is a Flex solution but the second gray box looks like ActionScript (though I'm not sure it is).  See if it can be of use:

http://stackoverflow.com/questions/342994/download-a-file-with-adobe-air

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 16, 2010 Nov 16, 2010

Thanks for all the suggested help, markerline!

That last one may work, but it's WAY over my realm of Flash knowledge, so I wouldn't even begin to be able to implement that.  I was hoping it would be more simple.

Unless something easier comes along, I guess I'll just go the .zip file route.  😕

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 16, 2010 Nov 16, 2010

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-7cf...

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 16, 2010 Nov 16, 2010

YOU'RE A GENIUS!  Thanks a ton!  That works perfectly!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 16, 2010 Nov 16, 2010
LATEST

Don't thank me, thank Google's internet search capabilities! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 16, 2010 Nov 16, 2010

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

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines