PDA

View Full Version : Download method for Flash 8



cortek
April 14th, 2007, 06:24 AM
Hi,

I was getting a little confused with how to make a button link download a file.

Apparently with Flash 8 you can embed the download link in flash.
I read that the "download();" method needs two parameters. The URL from where the file is being downloaded from, and the default File name for the download window.

Tried a couple of ways around it, couldn't get it to work.

Just wondering if anyone out there had used this and could point me in the right direction?

cheers

rabidGadfly
April 14th, 2007, 03:15 PM
Never worked with it. Are you importing the FileReference Class?

import flash.net.FileReference;;

matbury
April 14th, 2007, 05:48 PM
There's 2 parameters:

yourDownload.download("http://www.yoursite.com/downloadfolder", "thefile.txt");

the first is the URL

the second is a string specifying the default "save as" file name

the related methods are onCancel(), onOpen(), onProgress() and onComplete

for errors there's also onHTTPError(), onIOError() and onSecurityError()

You should be able to find what you need on the Flash help files.

cortek
April 15th, 2007, 11:57 PM
Hi, I'm calling the class and it's bringing up the download browser box, but then when i select a place on my computer to download to, it doesn't work.

Here's the code Im using that I modified from the help notes.
--------------------------------------------------------------------

btnWargame.onRelease = function () {
import flash.net.FileReference;
var listener:Object = new Object();

listener.onSelect = function(file:FileReference):Void {
trace("onSelect: " + file.name);
}

listener.onCancel = function(file:FileReference):Void {
trace("onCancel");
}

listener.onOpen = function(file:FileReference):Void {
trace("onOpen: " + file.name);
}

listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
}

listener.onComplete = function(file:FileReference):Void {
trace("onComplete: " + file.name);
}

listener.onIOError = function(file:FileReference):Void {
trace("onIOError: " + file.name);
}

var fileRef:FileReference = new FileReference();
fileRef.addListener(listener);
var url:String = "http://www.foreignlegionmusic.com/mp3s/amuzia/2/Wargame.mp3";
if(!fileRef.download("http://www.foreignlegionmusic.com/mp3s/amuzia/2/Wargame.mp3", "Wargame.mp3")) {
trace("dialog box failed to open.");
}
};

------------------------------------------------------------------
Can anyone see what im doing wrong in this code?
Any help is greatly appreciated.
Thanks in advance
Cortek