dedecms织梦内容管理系统    
首页 | java | C/C++ | PHP | 操作系统 | ajax | 脚本编程 | 安全技术 | 本站下载页 | flex | CRM | 专题 | QQ群 | 测试中心 | 会员中心 | 积分规则
  当前位置:主页>flex>文章内容
flex文件上传显示进度条
来源: 作者:

这是flex功能的一个亮点,而且读取进度条是从客户端读的,而不是服务端。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns
="*" creationComplete="init();">
    
<mx:Script>
        
<![CDATA[
            import flash.net.FileReference;
            import mx.controls.Alert;
            import mx.events.CloseEvent;
            import flash.events.*;

            private var file: FileReference;

            private function init(): void{
                Security.allowDomain("*");
                file = new FileReference();
                file.addEventListener(ProgressEvent.PROGRESS, onProgress);
                file.addEventListener(Event.SELECT, onSelect);
            }

            private function upload(): void{
                file.browse();
            }
            
            private function onSelect(e: Event): void{
                Alert.show("上传 " + file.name + " (共 "+Math.round(file.size)+" 字节)?",
                           "确认上传",
                           Alert.YES|Alert.NO,
                           null,
                           proceedWithUpload);
            }
            
            private function onProgress(e: ProgressEvent): void{
                lbProgress.text = " 已上传 " + e.bytesLoaded 
                    + " 字节,共 " + e.bytesTotal + " 字节";
                var proc: uint = e.bytesLoaded / e.bytesTotal * 100;
                bar.setProgress(proc, 100);
                 bar.label= "当前进度: " + " " + proc + "%";
            }
            
            private function proceedWithUpload(e: CloseEvent): void{
                if (e.detail == Alert.YES){
                    var request: URLRequest = new URLRequest(http://localhost/upload.jsp);
                    try {
                        file.upload(request);
                    } catch (error:Error) {
                        trace("上传失败");
                    }
                    
                }
            }
        
]]>
    
</mx:Script>
    
    
<mx:Canvas width="100%" height="100%">
        
<mx:VBox width="100%" horizontalAlign="center">
            
<mx:Label id="lbProgress" text="上传"/>
             
<mx:ProgressBar id="bar" labelPlacement="bottom" themeColor="#F20D7A"
                minimum
="0" visible="true" maximum="100" label="当前进度: 0%"  
                direction
="right" mode="manual" width="200"/>
            
<mx:Button label="上传文件" click="upload();"/>            
        
</mx:VBox>
    
</mx:Canvas>
</mx:Application>


上一篇:收取消息的activemq的例子   下一篇:hibernate登录例子代码
[收藏] [推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
用户名: 新注册) 密码: 匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论
  热点文章
·Flex 打印DataGrid内容
·Flex中的闪烁效果
·flex: 使用setInterval 制作定时
·FLEX优秀开源项目介绍
·AS3中的正则表达式
·flex确认提示(confirm window)
·Flex RemoteObject类参考
·flex:RemoteObject 和 DataGrid
·AS3的面向对象特点概述
·利用AS3的图形界面开发及资源管
·AS3.0 访问属性
·AS3.0强大的事件机制
  相关文章
·flex四舍五入
· flex(通过URLLoader)与后台jsp
·Flex学习进阶-使用
·
FLEX HTTPService 调用 ASP文件
·flex httpservice xml
·flex 如何使用HTTPService传值
·Flex HTTPService如何给后台传递
·flex存储和验证数据
·对Adobe Flex的十大误解
·用PrintingJob类自定义flex打印
·flex中的singleton(单例)模式
·ActionScript 3 中的可变长数组
  相关信息
copy right @ 百家拳软件项目研究室 2007 辽ICP备07011763