Flex上传文件功能
来源:互联网 发布:台服剑灵人女数据库 编辑:程序博客网 时间:2024/06/11 03:22
From: http://www.cnblogs.com/midea0978/archive/2008/08/06/1262260.html
写过很多文件上传的功能,包括AJAX实现动态监控上传进度的,现在看到了FLEX实现文件上传功能,还真是很方便,没什么好说的,上代码:
upload.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" layout="absolute" width="497" height="136" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#F2F8F8, #45E7E5]">
<mx:Script source="upload.as"></mx:Script>
<mx:Style>
.myfont{font-size:13pt}
</mx:Style>
<mx:Button x="10" y="95" label="上传文件" click="pickfile()" styleName="myfont"/>
<mx:Label x="10" y="10" text="文件上传" styleName="myfont"/>
<mx:ProgressBar x="10" y="40" width="457" themeColor="#F20D7A" minimum="0" mode="manual" maximum="100" id="progress1" label="当前进度: 0%" styleName="myfont" fontWeight="normal"/>
<mx:Label x="146" y="98" width="321" id="lbProgress" styleName="myfont" textAlign="right"/>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" layout="absolute" width="497" height="136" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#F2F8F8, #45E7E5]">
<mx:Script source="upload.as"></mx:Script>
<mx:Style>
.myfont{font-size:13pt}
</mx:Style>
<mx:Button x="10" y="95" label="上传文件" click="pickfile()" styleName="myfont"/>
<mx:Label x="10" y="10" text="文件上传" styleName="myfont"/>
<mx:ProgressBar x="10" y="40" width="457" themeColor="#F20D7A" minimum="0" mode="manual" maximum="100" id="progress1" label="当前进度: 0%" styleName="myfont" fontWeight="normal"/>
<mx:Label x="146" y="98" width="321" id="lbProgress" styleName="myfont" textAlign="right"/>
</mx:Application>
upload.as
1 // ActionScript file
2 import flash.events.Event;
3 import flash.net.FileFilter;
4 import flash.net.FileReference;
5 private var fileRef:FileReference = new FileReference();
6 private function init():void{
7
8 }
9
10 private function pickfile():void{
11 var imageTypes:FileFilter = new FileFilter("图片 (*.jpg, *.jpeg, *.gif,*.png)", "*.jpg; *.jpeg; *.gif; *.png");
12 var textTypes:FileFilter = new FileFilter("文本文件(*.txt","*.txt;");
13 var officeType:FileFilter = new FileFilter("Office文件(*.doc, *.xls","*.doc; *.xls");
14 var anyType:FileFilter = new FileFilter("所有文件(*.*)","*.*");
15 var allTypes:Array = new Array(imageTypes, textTypes,officeType,anyType);
16 fileRef.addEventListener(Event.SELECT, selectHandler);
17 fileRef.addEventListener(Event.COMPLETE, completeHandler);
18 fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);
19 fileRef.addEventListener("ioError", ioerrorHandler);
20 try{
21 var success:Boolean = fileRef.browse(allTypes);
22 }catch (error:Error){
23 trace("Unable to browse for files."+error.toString());
24 }
25 }
26 private function ioerrorHandler(event:Event):void{
27 trace("Unable to upload file."+event.toString());
28 }
29 private function progressHandler(event:ProgressEvent):void{
30 lbProgress.text = " 已上传 " + (event.bytesLoaded/1024).toFixed(2)+ " K,共 " + (event.bytesTotal/1024).toFixed(2) + " K";
31 var proc: uint = event.bytesLoaded / event.bytesTotal * 100;
32 progress1.setProgress(proc, 100);
33 progress1.label= "当前进度: " + " " + proc + "%";
34
35 }
36 private function selectHandler(event:Event):void{
37 var request:URLRequest = new URLRequest("http://localhost:9080/upload/upload.jsp")
38 try
39 {
40 fileRef.upload(request);
41 }
42 catch (error:Error)
43 {
44 trace("Unable to upload file."+error.toString());
45 }
46 }
47 private function completeHandler(event:Event):void{
48 trace("uploaded");
49 }
50
51
2 import flash.events.Event;
3 import flash.net.FileFilter;
4 import flash.net.FileReference;
5 private var fileRef:FileReference = new FileReference();
6 private function init():void{
7
8 }
9
10 private function pickfile():void{
11 var imageTypes:FileFilter = new FileFilter("图片 (*.jpg, *.jpeg, *.gif,*.png)", "*.jpg; *.jpeg; *.gif; *.png");
12 var textTypes:FileFilter = new FileFilter("文本文件(*.txt","*.txt;");
13 var officeType:FileFilter = new FileFilter("Office文件(*.doc, *.xls","*.doc; *.xls");
14 var anyType:FileFilter = new FileFilter("所有文件(*.*)","*.*");
15 var allTypes:Array = new Array(imageTypes, textTypes,officeType,anyType);
16 fileRef.addEventListener(Event.SELECT, selectHandler);
17 fileRef.addEventListener(Event.COMPLETE, completeHandler);
18 fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);
19 fileRef.addEventListener("ioError", ioerrorHandler);
20 try{
21 var success:Boolean = fileRef.browse(allTypes);
22 }catch (error:Error){
23 trace("Unable to browse for files."+error.toString());
24 }
25 }
26 private function ioerrorHandler(event:Event):void{
27 trace("Unable to upload file."+event.toString());
28 }
29 private function progressHandler(event:ProgressEvent):void{
30 lbProgress.text = " 已上传 " + (event.bytesLoaded/1024).toFixed(2)+ " K,共 " + (event.bytesTotal/1024).toFixed(2) + " K";
31 var proc: uint = event.bytesLoaded / event.bytesTotal * 100;
32 progress1.setProgress(proc, 100);
33 progress1.label= "当前进度: " + " " + proc + "%";
34
35 }
36 private function selectHandler(event:Event):void{
37 var request:URLRequest = new URLRequest("http://localhost:9080/upload/upload.jsp")
38 try
39 {
40 fileRef.upload(request);
41 }
42 catch (error:Error)
43 {
44 trace("Unable to upload file."+error.toString());
45 }
46 }
47 private function completeHandler(event:Event):void{
48 trace("uploaded");
49 }
50
51
效果图:
- Flex上传文件功能
- 使用Flex实现FTP文件上传功能
- Flex上传功能实现
- flex 文件上传
- Flex + servlet 上传文件
- flex+php文件上传
- flex 多文件上传
- flex上传文件
- Flex文件上传
- Flex FTP文件上传
- flex +jsp 文件上传
- flex文件上传1
- flex多文件上传
- FLEX文件上传
- Flex文件上传
- flex+struts2上传文件
- Flex 文件上传
- Flex多文件上传
- Linux-网桥原理分析 .
- 前端在开发过程中可能用的一些简单的功能的收集
- CStatusBar和CStatusBarCtrl的区别以及使用注意事项
- dede sql 用法
- sharepoint 2010 custom webpart与custom webpart的联动方法
- Flex上传文件功能
- ubuntu 用户/用户组管理
- Some projects cannot be imported because they already exist in the workspace
- 一步到位设置linux系统时间
- 如何配置Visual Studio 2010中的ASP.NET MVC的单元测试的代码覆盖率
- 在oracle中计算时间差
- suse linux原创案例03: Give root password for maintenance
- 指针
- Trim the Nails (DFS+状态压缩) #by Plato