Copy link to clipboard
Copied
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!
I found a much simpler solution "Downloading files from a Server" on this page:
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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:
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.
Copy link to clipboard
Copied
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.*
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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. 😕
Copy link to clipboard
Copied
I found a much simpler solution "Downloading files from a Server" on this page:
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.
Copy link to clipboard
Copied
YOU'RE A GENIUS! Thanks a ton! That works perfectly!!!
Copy link to clipboard
Copied
Don't thank me, thank Google's internet search capabilities!
Copy link to clipboard
Copied
Here is a similar thread with a similar question as yours:
Find more inspiration, events, and resources on the new Adobe Community
Explore Now