//获取上传文件名
System.useCodePage=true;
var uploadURL:URLRequest;
var file:FileReference;
file = new FileReference();
file.addEventListener(Event.SELECT, selectHandler);
file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
file.addEventListener(Event.COMPLETE, completeHandler);
//file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,dataHandler);
function selectHandler(event:Event):void {
uploadTxt.text = file.name;
}
function ioErrorHandler(event:IOErrorEvent):void {
uploadTxt.text ="上传失败...";
}
function progressHandler(event:ProgressEvent):void {
var file:FileReference = FileReference(event.target);
uploadTxt.text ="正在上传..."+int((event.bytesLoaded/event.bytesTotal)*100)+"%";
}
function completeHandler(event:Event):void {
uploadTxt.text ="上传完毕..."
;
}
function dataHandler(data:DataEvent):void {
if (data.data==1) {
uploadTxt.text ="上传完毕...";
} else {
uploadTxt.text ="上传失败...";
}
}
//浏览功能
browseBtn.addEventListener(MouseEvent.MOUSE_DOWN,browse);
function browse(e:Event) {
var fileFilter:FileFilter = new FileFilter("课件类型", "*.swf;*.ppt;*.rar");
file.browse([fileFilter]);
}
//上传功能
uploadBtn.addEventListener(MouseEvent.MOUSE_DOWN,upload);
function upload(e:Event) {
//先检查文件是不是FLV
fileType = file.type;
fileSize=file.size;
trace("大小:"+fileSize);
if (fileSize>1024*1024*1000) {
uploadTxt.text ="文件太大!";
} else {
savedName =escape(file.name);
parent.savedName=savedName;
uploadURL = new URLRequest();
uploadURL.url =parent.iisPath+"UploadScript.asp?userName="+parent.userName+"&uploadName="+savedName;
file.upload(uploadURL);
trace(uploadURL.url)
}
}