我终于在我放在这里的类的代码中找到了解决这个问题的方法。您只需为每个下载文件添加(在 .fla 中)一个按钮、两个相同的条 (mc) 以指示进度(“mc_progress”和“mc_loaded”)和一个文本字段以了解操作已完成(txt_prog.文本)。就是这样。您可以在这里找到全部内容:http: //dev.tutsplus.com/tutorials/quick-tip-download-files-through-swfs-using-filereference--active-9068
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.net.FileReference;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.events.Event;
public class fileref extends Sprite
{
//Donload Buttons
public var btn_img_download : MovieClip,
btn_txt_download : MovieClip,
btn_mp3_download : MovieClip,
mc_loaded : MovieClip;
//Progress Bar
public var mc_progress : MovieClip,
txt_prog : TextField;
//Download links Array
private var Arr_Links : Array;
//Default Parent Path for Downloads
private var defaultPath : String = "files/";
//Filen Name
private var urlName : String;
//instance of FileReference() Class
private var fr : FileReference;
//url of the requested files
private var req : URLRequest;
public function fileref() : void
{
//Set buttonModes of the download buttons
btn_img_download.buttonMode = btn_txt_download.buttonMode = btn_mp3_download.buttonMode = true;
//Set width of the mc_loaded progress bar to 0
mc_loaded.scaleX = 0;
//Create list of files to be downloaded
Arr_Links = ["myimage.jpg","myaudio.mp3","mytext.rtf"];
req = new URLRequest();
fr = new FileReference();
//Download buttons Event Listeners
btn_img_download.addEventListener( MouseEvent.CLICK,downloadFile );
btn_mp3_download.addEventListener( MouseEvent.CLICK,downloadFile );
btn_txt_download.addEventListener( MouseEvent.CLICK,downloadFile );
fr.addEventListener( ProgressEvent.PROGRESS,progressHandler );
fr.addEventListener( Event.COMPLETE,completeHandler );
}
private function downloadFile( e : MouseEvent ) : void
{
//set the download path to the urlName variable according to clicked Download Button
switch (e.target.name)
{
case "btn_img_download":
urlName = Arr_Links[0];
break;
case "btn_mp3_download":
urlName = Arr_Links[1];
break;
case "btn_txt_download":
urlName = Arr_Links[2];
break;
}
//change text message "progress" to "downloading..." at txt_prog
txt_prog.text = "downloading...";
//Assign url to the req
req.url = defaultPath + urlName;
//Downlaod requested file
fr.download( req );
}
private function progressHandler( event : ProgressEvent ) : void
{
mc_loaded.scaleX = (event.bytesLoaded / event.bytesTotal) ;
}
private function completeHandler( event : Event ) : void
{
//reset progress bar after download is finished
mc_loaded.scaleX = 0;
txt_prog.text = "download finished";
}
}
}