I am wondering if there is an easy way to link files to a flash website so users are able to download the file to their local computer. What I have tried so far is to make a button and then use AS to do a getURL to try and link it to a local file in the same directory but by the lack of progress I have made I am guessing it is not possible that way if at all? Any pointers or suggestings would be appriciated, and just as a side note, I am a novice to Flash and AS yet.
You should show the code you are trying to use. If you are using AS3 and tried using getURL, then that will be part of the problem since getURL is AS2 code. As3 uses navigateToURL.
An alternative approach would be to use the FileReference class. YOu can search Google for a tutorial. Here's onwe result from searching "AS3 FileReference download tutorial"
Thanks for the head start Ned, here is what I have so far. In my actual .fla file I have a button made that is a movie clip that is called btn_dummy, I don't have any action script programmed for the button on my .fla file (which is correct according to the tutorial, but it seems weird to have nothing at all) My class, which is called "files.as" is below
public class files extends MovieClip
//Download Buttons at the Stage.We have to define them as public variables in our Document Class in order to use them.
//Otherwise, we get error message from Flash.
public var btn_dummy : MovieClip;
//Arr_Links hold the list of files.
private var Arr_Links : Array;
//Default Path where the download is stored.
//You change it according to your setup.
//This is relative to the SWF.
private var defaultPath : String = "files/";
private var urlName : String;
//instance of FileReference() Class
private var fr : FileReference;
//url of the requested files
private var req : URLRequest;
public function files() : void
//Set buttonMode to true to change mouse curser to hand icon
btn_dummy.buttonMode = true;
//Create list of files to be downloaded
//These files must be in the folder specified by defaultPath
Arr_Links = ["dummy.zip"];
//Create a request object
req = new URLRequest();
//Create an instance of the FileReference Class
fr = new FileReference();
//Event Listeners for Download Buttons
//When user clicks any download button, call downloadFile(e:MouseEvent) function
btn_dummy.addEventListener( MouseEvent.CLICK,downloadFile );
private function downloadFile( e : MouseEvent ) : void
//set the download path to the urlName variable according to clicked Download Button
urlName = Arr_Links;
//Assign url to the req variable
req.url = defaultPath + urlName;
//Downlaod requested file
fr.download( req );
When I run this, I get the following error message:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
The problem is at this line I know: public function files() : void
But I don't know why it is giving it to me, I followed the tutorial, I am sure it is something really easy, I have been trying to figure it out for 5 hours now and I am sure sitting and staring ath the code doesn't help things, lol. But if I could get some pointers, or at least if somebody could point me in the direction where there is information that could help me out, I would greatly appriciate it.