加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex文件上传

发布时间:2020-12-15 01:12:09 所属栏目:百科 来源:网络整理
导读:?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; imp
<?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/JZService/WebForm1.aspx");
                    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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读