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

flex上传

发布时间:2020-12-15 04:22:31 所属栏目:百科 来源:网络整理
导读:? 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]" ?backgroundGradientColor
<? 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:Button? x ="10" ?y ="95" ?label ="上传文件" ?click ="pickfile()" ?styleName ="myfont" />
????
mx:Label? ?text ="文件上传" mx:ProgressBar? ="40" ="457" ?themeColor ="#F20D7A" ?minimum ="0" ?mode ="manual" ?maximum ="100" ?id ="progress1" ="当前进度:?0%" ="myfont" ?fontWeight ="normal" ="146" ="98" ="321" ="lbProgress" ?textAlign ="right" />

</mx:Application>


// ActionScript file ?import flash.events.Event; ?import flash.net.FileFilter; ?import flash.net.FileReference; ?private var fileRef:FileReference = new FileReference(); ?private function init():void{ ? ? ? ?} ? ?private function pickfile():void{ ? ? ?var imageTypes:FileFilter = new FileFilter("图片 (*.jpg,*.jpeg,*.gif,*.png)","*.jpg; *.jpeg; *.gif; *.png"); ? ? ?var textTypes:FileFilter = new FileFilter("文本文件(*.txt","*.txt;"); ? ? ?var officeType:FileFilter = new FileFilter("Office文件(*.doc,*.xls","*.doc; *.xls"); ? ? ?var anyType:FileFilter = new FileFilter("所有文件(*.*)","*.*"); ? ? ?var allTypes:Array = new Array(imageTypes,textTypes,officeType,anyType); ? ? ?fileRef.addEventListener(Event.SELECT,selectHandler); ? ? ?fileRef.addEventListener(Event.COMPLETE,completeHandler); ? ? ?fileRef.addEventListener(ProgressEvent.PROGRESS,progressHandler); ? ? ?fileRef.addEventListener("ioError",ioerrorHandler); ? ? ?try{ ? ? ? ? ?var success:Boolean = fileRef.browse(allTypes); ? ? ?}catch (error:Error){ ? ? ? ? ?trace("Unable to browse for files."+error.toString()); ? ? ?} ?} ?private function ioerrorHandler(event:Event):void{ ? ? ?trace("Unable to upload file."+event.toString()); ?} ?private function progressHandler(event:ProgressEvent):void{ ? ? ?lbProgress.text = " 已上传 " + (event.bytesLoaded/1024).toFixed(2)+ " K,共 " + (event.bytesTotal/1024).toFixed(2) + " K"; ? ? ?var proc: uint = event.bytesLoaded / event.bytesTotal * 100; ? ? ?progress1.setProgress(proc,100); ? ? ?progress1.label= "当前进度: " + " " + proc + "%"; ? ?} ?private ? ?function selectHandler(event:Event):void{ ? ? ?var request:URLRequest = new URLRequest("http://localhost:9080/upload/upload.jsp") ? ? ?try ? ? ?{ ? ? ? ? ?fileRef.upload(request); ? ? ?} ? ? ?catch (error:Error) ? ? ?{ ? ? ? ? ?trace("Unable to upload file."+error.toString()); ? ? ?} ?} ?private function completeHandler(event:Event):void{ ? ? ?trace("uploaded"); ?}

(编辑:李大同)

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

    推荐文章
      热点阅读