AS3.0上传示例

发布时间:2024年01月21日

//获取上传文件名
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)
?}
}

文章来源:https://blog.csdn.net/XiBuQiuChong/article/details/135732196
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。