Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / General Flash Topics / July 2008



Tip: Looking for answers? Try searching our database.

How To: Create Download Mp3 Link

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mattyfuse - 02 Jul 2008 01:56 GMT
Hello fellow flash users-

I have been building my website in flash and have a simple question that I
cannot figure out for some reason (maybe its too simple) . Anyhow I have
uploaded my mp3 songs of my music and used the geturl and _blank so that when
someone clicks on my link the music opens right into thier quicktime player (if
on mac) or windows media player (if on pc). I want the user to be able to
download the mp3 to there computer (ie like a normal download window appears
stating "do you want to download this file to disk" is there some other code or
line I need to add ???? It seems so simple? I would really appreciate the help
as I have tried a number of things with no success. Thanks!

Matt
Noelbaland - 02 Jul 2008 04:21 GMT
Hello there,

There's a class in Actionscript 2 called the FileRefence class.  This could be
what you're looking for.  Below is a script I used to download a PDF file from
a button.  Try it and see if it works for you.  
You should read more about the FileRefence class as there is a lot of
information not included in the following code.

Hope it helps
mattyfuse - 02 Jul 2008 05:54 GMT
Hi Noelbaland

thanks for the response -

Where do I place the code so I do not get error messages - currently I have a
button and right clicked the button and selected actions then have the code
witin

on (release) {
    getURL("http://www.mysite.com/mysound.mp3","_blank");
}

when I replace the your code within mine I get all  kinds of errors - where am
I supposed to position the code you listed? Thanks!!!
mattyfuse - 02 Jul 2008 05:56 GMT
...meaning do I place it within the on (release) code - I keep getting syntax errors and out of place { }

thanks~!
Noelbaland - 02 Jul 2008 06:29 GMT
Hello again,

Leave your current button as is.  Create another button under that one. Attach
the following to the button.

on(release){
     downloadMP3("myMP3.mp3");
}

The rest of the code goes above it on a frame in the main timeline.  

import flash.net.FileReference;

function downloadMP3(filename)
{
     var listener:Object = new Object();
     listener.onComplete = function(file:FileReference) {
          trace("onComplete : " + file.name);
     }

     var url:String = "http://www.myflashwebsite.html/";
     var fileRef:FileReference = new FileReference();
     fileRef.addListener(listener);
     fileRef.download(url, filename);
}

I missed something in the previous code.  The filename variable in the
downloadMP3 function above allows you to download any MP3 file that you have.  
Just attach the same code to another button and call a different mp3 file.
mattyfuse - 02 Jul 2008 15:30 GMT
Thanks a lot for the help Noelbaland - After I get home from work I will do this and let you know how it turns out
mattyfuse - 03 Jul 2008 02:04 GMT
Hey Noelbaland,

So I just placed the code in my site and everything appears to be working with
no errors but when I click on the button online the download box appears and
the file name is correct but nothing downloads - In fact there is no status bar
or anything? Do you have any idea what I might be doing wrong - I feel so close
to getting it ! Thanks

here is what I put in

I placed the code on a random frame within the actions

import flash.net.FileReference;

function downloadMP3(filename)
{
var listener:Object = new Object();
listener.onComplete = function(file:FileReference) {
trace("onComplete : " + file.name);
}

var url:String = "http://www.myflashwebsite.html/";
var fileRef:FileReference = new FileReference();
fileRef.addListener(listener);
fileRef.download(url, filename);
}

then I replaced the button actions code with

on(release){
downloadMP3("myMP3.mp3");
}

and the button works, as I said it just doesnt download anything? Any
ideas????

Thanks!!
mattyfuse - 03 Jul 2008 02:06 GMT
also the only thing i need to change from your code is the

http://www.. etc

and the action mp3 name correct?
Noelbaland - 03 Jul 2008 05:14 GMT
Hi mattyfuse,

Ok, after some testing and a few changes in the script I've come up with a
version that works (well, for me anyway).
I've used a dynamic textbox called statusText to show me the download
progress.  You will need to create one for your movie (just for testing
purposes).
Here's the code
mattyfuse - 03 Jul 2008 20:59 GMT
hey Noelbaland

Just wanna through out a HUGE thank you for your help with this - I really
really appreciate it and I finally got it working thanks to you - I still cant
figure out how to create the progress and finisehd downloading windows plus I
found out you can only download 1 file at a time, as the temporary flash file
gets overwritten when you click on another download while the other one is
still going.  I will keep working on making this all work - but thanks again
for all your help!!!!!!!
mattyfuse - 03 Jul 2008 21:20 GMT
Btw Noelbaland

Not sure how much you have used the filereference code but I am finding a lot
of issues with it. For one - The user must STAY on the exact page while the
entire download finishes or it will cease and disappear.  There is no way to
tell how much the download has already done and there is no finished note to
the user. Normally in the mac the download folder appears and it shows progress
and will give me a warning that I am downloading files before I exit out of
safari. Do you have any idea of a work around or know and other suggestions or
better methods (the files I have for download are quite large so it would be
weird to ask the user not to close out of the page so the download can finish.  
Thanks!!!!
Noelbaland - 04 Jul 2008 04:45 GMT
Hello mattyfuse,

Oh - OK - now I see what it is you're after.  This whole time I thought you
were wanting to create a way of downloading a file using the Flash player.  
You're actually after a normal download type situation like if you're in a
regular HTML page.  Where the browsers GUI is used to prompt you with panels
for progress and completion of downloads.

As far as Flash is concerned, the FileReference object is limited in it's
control of the GUI tools in the browser.  Apart from a few more commands, the
script I showed you above is basically it.  You are right that you have to
"STAY in the exact page" because that's how a Flash movie works.  You close the
page - you close the movie (and consequently, any downloads).

You can make the Flash movie behave like the browser tools by building your
own preloaders, info panels, and prompt boxes.  But this would require a lot
more work on your behalf and you would need a good knowledge of Actionscript.  
And again, you would still have to STAY in the exact page!

My only workaround is to perhaps zip your mp3 files and have a button that
points to it.  That way it'll behave like a regular file and trigger the
browsers default download functions.
You can use the same script that you use to open the mp3 file.  

on(release){
getURL("http://www.mysite.com/mysong.zip", "_blank");
}

Hope that helps
mattyfuse - 06 Jul 2008 20:13 GMT
hey Noelbaland

thanks for all your help - I  am going to go with the zip technique you suggested as that will work best for the purpose of the site - thanks again I really appreciate it
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.