日期:2013-12-15 浏览次数:20691 次
import flash.net.FileReference;
var listener:Object = new Object();
var btListener:Object = new Object();
var file:FileReference = new FileReference();
var isLoading:Boolean = false;
var url:String = "http://count.skycn.com/softdownload.php?id=4934&url=http://tj-http.skycn.net:8081/down/IPQQ2005_skycn.exe";
bt.label = "开始下载";
downLoadBar.mode = "manual";
downLoadBar._visible = false;
listener.onProgress = function(file:FileReference, loaded:Number, total:Number):Void {
downLoadBar.label = "已完成:"+int(loaded/total*100)+"%";
downLoadBar.setProgress(loaded,total);
}
btListener.click = function():Void{
if(!isLoading){
bt.label = "取消";
file.download(url,"QQ.exe.tmp");//FileReference的download方法,参数一:下载文件的URL,参数二:保存到本地的默认文件名
isLoading = true;
downLoadBar._visible = true;
}else if(isLoading){
bt.label = "开始下载";
file.cancel();
isLoading = false;
downLoadBar._visible = false;
}
}
file.addListener(listener);
bt.addEventListener("click",btListener);
//基本上实现的方法不难.不过我想到的FLASH提供的这个方法可以为一些做资源下载服务的站长带来喜讯了--不怕资源被轻易盗链了,哈哈.而且使用FLASH8提供的文件下载接口给用户提供下载服务的话在一定程度上能够强制性的给客户端一个操作管理.