6 Replies Latest reply on Aug 7, 2006 4:43 PM by Craig Grummitt

    Download button

    kenshamrock
      I have a download button on my site that when its pressed i want a pop up box to appear, where u can choose where to save the file to.
      anyone have any ideas on the coding for such a button.
        • 1. Re: Download button
          Vision Designs
          Try this code - Be sure to name the button instance, file path to where the file is on the server., and the name of the file people see when they click on it.




          import flash.net.FileReference;


          var fileRef:FileReference = new FileReference();
          var url:String = " http://www.YOUR COMPLETE INTERNET ADDRESS GOES HERE";
          NAME OF BUTTON INSTANCE.onPress=function(){
          fileRef.download(url, "THE NAME OF THE FILE YOU WANT PEOPLE SEE ");
          }
          • 2. Re: Download button
            kenshamrock Level 1
            u have to excuse me im very new to flash.

            Tried the code but theres an error

            **Error** Scene=Scene 1, layer=button1d, frame=149:Line 4: The class 'flash.net.FileReference' could not be loaded.
            var fileRef:FileReference = new FileReference();

            Total ActionScript Errors: 1 Reported Errors: 1
            • 3. Re: Download button
              kenshamrock Level 1
              i have to bump this, its becoming quite urgent .
              • 4. Re: Download button
                Vision Designs Level 1
                It looks like maybe you didn't name the "instance" on the button. Also make sure the button is at the end of the timeline with action script at the end too. Let me know.....
                • 5. Re: Download button
                  WebXperience Level 1
                  The following example attempts to download a file using the download method. Notice that there are listeners for all of the events.

                  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.macromedia.com/platform/whitepapers/platform_overview.pdf";
                  if(!fileRef.download(url, "FlashPlatform.pdf")) {
                  trace("dialog box failed to open.");
                  }



                  See also
                  browse (FileReference.browse method), browse (FileReferenceList.browse method), upload (FileReference.upload method)

                  • 6. Download button
                    Craig Grummitt Level 3
                    You will need Flash 8 to use the FileReference class(and you need to output for Flash 8 player).