惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
Y
Y Combinator Blog
月光博客
月光博客
IT之家
IT之家
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
L
LangChain Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
博客园 - Franky
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
V
Visual Studio Blog
小众软件
小众软件
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium

博客园 - 在路上...

Iphone的HEIC图片文件格式转换及相关开发工具 账号复活了 2015年,即将结束 CentOS 6 minimal 安装之后添加gnome Windows8离线安装.net framework 3.5 新年快到了,此记 flex中ComboBox对应的几种数据绑定 - 在路上... - 博客园 Jquery中增加参数与Json转换代码 - 在路上... - 博客园 如何获取到informix for linux? 建国大业 《红》mp3下载 T42内存升级 随便一帖 Informix 9.40UC9 on Redhat Linux AS 4安装手记 Taking the web Offline and On the Desktop Flex实现QQ网页提取天气信息 乱弹ruby on rails目录下面的文件数有3万多个 Ruby on rails 2.0.2傻瓜入门之Hello world Javascript代码压缩、加密算法的破解分析及工具实现 【翻译】Oracle不同版本之间Export & Import的兼容性矩阵
Flex上传文件功能
在路上... · 2008-08-06 · via 博客园 - 在路上...

写过很多文件上传的功能,包括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>

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 

效果图: