Hi,
I am using this code to download a file from a server (podcast episode mp3) but I click the submit button and nothing happens. The text field shows “Downloading episode X” but nothing happens, no browse-to-save window pops up or anything. Here is my entire code, no external.
It simply uses AMFPHP to drawback results to see if the podcast episode exists. If it returns a 1, the fileReference download is triggered. I’m pretty sure the rest of the code is fine, its just the “localRef.download(requestF);” bit that seems to be doing nothing.
[LEFT][COLOR=#993300]import[/COLOR] flash.[COLOR=#000000]net[/COLOR].*;
Security.[COLOR=#000000]loadPolicyFile[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]"http://www.example.com/crossdomain.xml"[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#993300]var[/COLOR] context:LoaderContext = [COLOR=#993300]new[/COLOR] LoaderContext[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#993300]var[/COLOR] fileName:[COLOR=#993300]String[/COLOR];
context.[COLOR=#000000]checkPolicyFile[/COLOR] = [COLOR=#993300]true[/COLOR];
loader_mc.[COLOR=#993300]visible[/COLOR] = [COLOR=#993300]false[/COLOR];
[COLOR=#f000f0]*// Set textbox to "loading latest episode.." before AMFPHP info is called.*[/COLOR]
output_txt.[COLOR=#993300]text[/COLOR] = [COLOR=#0000ff]"Loading latest episode....."[/COLOR];
[COLOR=#f000f0]*// Make the connection to AMFPHP*[/COLOR]
[COLOR=#993300]var[/COLOR] gw:[COLOR=#993300]NetConnection[/COLOR] = [COLOR=#993300]new[/COLOR] [COLOR=#993300]NetConnection[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
gw.[COLOR=#993300]connect[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]"http://www.example.com/amfphp/gateway.php"[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*// Set the variable for calling latest episode*[/COLOR]
[COLOR=#993300]var[/COLOR] latest:Responder = [COLOR=#993300]new[/COLOR] Responder[COLOR=#000000]([/COLOR]onLatest[COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*// And finally call the latest episode*[/COLOR]
gw.[COLOR=#993300]call[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]"downloader.latestEpisode"[/COLOR], latest[COLOR=#000000])[/COLOR];
submit_btn.[COLOR=#000000]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000000]MOUSE_UP[/COLOR], sendEp[COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*// -----------------------------------------------------------------*[/COLOR]
[COLOR=#f000f0]*// Send latest episode straight to text box "output_txt"*[/COLOR]
[COLOR=#993300]function[/COLOR] onLatest[COLOR=#000000]([/COLOR]latest:[COLOR=#993300]Object[/COLOR][COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#993300]var[/COLOR] latestEp:[COLOR=#993300]String[/COLOR] = [COLOR=#993300]String[/COLOR][COLOR=#000000]([/COLOR]latest[COLOR=#000000])[/COLOR]
output_txt.[COLOR=#993300]text[/COLOR] = [COLOR=#0000ff]"Latest Episode: "[/COLOR] + latestEp;
[COLOR=#000000]}[/COLOR]
[COLOR=#f000f0]*// Heres all the fileReference and download stuff in a function.*[/COLOR]
[COLOR=#993300]var[/COLOR] localRef:FileReference = [COLOR=#993300]new[/COLOR] FileReference[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#993300]function[/COLOR] doDownload[COLOR=#000000]([/COLOR]episode:[COLOR=#993300]String[/COLOR][COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#993300]var[/COLOR] requestF:URLRequest = [COLOR=#993300]new[/COLOR] URLRequest[COLOR=#000000]([/COLOR][COLOR=#0000ff]"http://www.example.com/episodes/"[/COLOR] + episode + [COLOR=#0000ff]".mp3"[/COLOR][COLOR=#000000])[/COLOR];
localRef.[COLOR=#000000]download[/COLOR][COLOR=#000000]([/COLOR]requestF[COLOR=#000000])[/COLOR];
localRef.[COLOR=#000000]addEventListener[/COLOR][COLOR=#000000]([/COLOR]ProgressEvent.[COLOR=#000000]PROGRESS[/COLOR], progressHandler[COLOR=#000000])[/COLOR];
localRef.[COLOR=#000000]addEventListener[/COLOR][COLOR=#000000]([/COLOR]Event.[COLOR=#000000]COMPLETE[/COLOR], completeHandler[COLOR=#000000])[/COLOR];
localRef.[COLOR=#000000]addEventListener[/COLOR][COLOR=#000000]([/COLOR]Event.[COLOR=#000000]CANCEL[/COLOR], cancelHandler[COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*//fileName = "episode" + input.text + ".mp3"; *[/COLOR]
loader_mc.[COLOR=#993300]visible[/COLOR] = [COLOR=#993300]true[/COLOR];
loader_mc.[COLOR=#000000]scaleX[/COLOR] = [COLOR=#000000]0[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#f000f0]*// Do some progress bar handling*[/COLOR]
[COLOR=#993300]function[/COLOR] progressHandler[COLOR=#000000]([/COLOR]evt:ProgressEvent[COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]var[/COLOR] percentage:[COLOR=#993300]Number[/COLOR] = [COLOR=#000000]0[/COLOR];
[COLOR=#993300]if[/COLOR] [COLOR=#000000]([/COLOR]evt.[COLOR=#000000]bytesTotal[/COLOR]>[COLOR=#000000]0[/COLOR][COLOR=#000000])[/COLOR]
percentage=evt.[COLOR=#993300]bytesLoaded[/COLOR]/evt.[COLOR=#993300]bytesTotal[/COLOR];
loader_mc.[COLOR=#000000]scaleX[/COLOR] = percentage;
output_txt.[COLOR=#993300]text[/COLOR] = [COLOR=#0000ff]"Download Progress: "[/COLOR] + [COLOR=#993300]Math[/COLOR].[COLOR=#993300]round[/COLOR][COLOR=#000000]([/COLOR]percentage * [COLOR=#000000]100[/COLOR][COLOR=#000000])[/COLOR] + [COLOR=#0000ff]"%"[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]function[/COLOR] completeHandler[COLOR=#000000]([/COLOR]evt:Event[COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR] [COLOR=#000000]{[/COLOR]
output_txt.[COLOR=#993300]text[/COLOR] = [COLOR=#0000ff]"Download Complete!!"[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]function[/COLOR] cancelHandler[COLOR=#000000]([/COLOR]event:Event[COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR] [COLOR=#000000]{[/COLOR]
output_txt.[COLOR=#993300]text[/COLOR] = [COLOR=#0000ff]"Cancelled download"[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#f000f0]*// -------------------------------------------------------------------*[/COLOR]
[COLOR=#f000f0]*// Send result to textbox and load episode download if true.*[/COLOR]
[COLOR=#993300]function[/COLOR] onFetch[COLOR=#000000]([/COLOR]res:[COLOR=#993300]Object[/COLOR][COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#993300]var[/COLOR] epResult:[COLOR=#993300]String[/COLOR] = [COLOR=#993300]String[/COLOR][COLOR=#000000]([/COLOR]res[COLOR=#000000])[/COLOR];
[COLOR=#993300]if[/COLOR][COLOR=#000000]([/COLOR]epResult==[COLOR=#0000ff]"empty"[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
output_txt.[COLOR=#993300]text[/COLOR] = [COLOR=#0000ff]"You need to enter something in!"[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]if[/COLOR][COLOR=#000000]([/COLOR]epResult==[COLOR=#0000ff]"code"[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
output_txt.[COLOR=#993300]text[/COLOR] = [COLOR=#0000ff]"Opening browser window.."[/COLOR]
[COLOR=#993300]var[/COLOR] Location:URLRequest = [COLOR=#993300]new[/COLOR] URLRequest [COLOR=#000000]([/COLOR][COLOR=#0000ff]"http://www.example.com/tent/getlink.php?code="[/COLOR] + input.[COLOR=#993300]text[/COLOR][COLOR=#000000])[/COLOR];
navigateToURL [COLOR=#000000]([/COLOR]Location, [COLOR=#0000ff]"_tab"[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]if[/COLOR][COLOR=#000000]([/COLOR]epResult==[COLOR=#0000ff]"noonly"[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
output_txt.[COLOR=#993300]text[/COLOR] = [COLOR=#0000ff]"Numbers only!"[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]if[/COLOR][COLOR=#000000]([/COLOR]epResult==[COLOR=#0000ff]"noexist"[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
output_txt.[COLOR=#993300]text[/COLOR] = [COLOR=#0000ff]"Episode "[/COLOR] + input.[COLOR=#993300]text[/COLOR] + [COLOR=#0000ff]" doesn't exist!"[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]if[/COLOR][COLOR=#000000]([/COLOR]epResult==[COLOR=#0000ff]"2"[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
doDownload[COLOR=#000000]([/COLOR][COLOR=#0000ff]"bloopers"[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]if[/COLOR][COLOR=#000000]([/COLOR]epResult==[COLOR=#0000ff]"1"[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
output_txt.[COLOR=#993300]text[/COLOR] = [COLOR=#0000ff]"Downloading episode "[/COLOR] + input.[COLOR=#993300]text[/COLOR] + [COLOR=#0000ff]"....."[/COLOR];
doDownload[COLOR=#000000]([/COLOR][COLOR=#0000ff]"episode"[/COLOR] + input.[COLOR=#993300]text[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#f000f0]*// When the submit button is pressed, do all of this:*[/COLOR]
[COLOR=#993300]function[/COLOR] sendEp[COLOR=#000000]([/COLOR]event:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]var[/COLOR] res:Responder = [COLOR=#993300]new[/COLOR] Responder[COLOR=#000000]([/COLOR]onFetch[COLOR=#000000])[/COLOR];
[COLOR=#f000f0]*// Set loading as text once button is pushed.*[/COLOR]
output_txt.[COLOR=#993300]text[/COLOR] = [COLOR=#0000ff]"Loading....."[/COLOR];
[COLOR=#f000f0]*// Set the variable for calling the results after submit*[/COLOR]
gw.[COLOR=#993300]call[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]"downloader.getEpisode"[/COLOR], res, input.[COLOR=#993300]text[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#f000f0]*// We're done here. :) *[/COLOR]
[/LEFT]
I think it has something to do with the submit_btn listener not listening properly.
Can anyone help?
Thanks.