自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

學(xué)習(xí)筆記 剖析Flex上傳文件功能如何實(shí)現(xiàn)

開(kāi)發(fā) 后端
Flex有很多值得學(xué)習(xí)的地方,本文向大家介紹一下Flex上傳文件功能,相信本文介紹一定會(huì)讓你有所收獲,歡迎大家一起來(lái)學(xué)習(xí)。

本文和大家重點(diǎn)討論一下Flex上傳文件功能如何實(shí)現(xiàn),寫(xiě)過(guò)很多文件上傳的功能,包括AJAX實(shí)現(xiàn)動(dòng)態(tài)監(jiān)控上傳進(jìn)度的,現(xiàn)在看到了實(shí)現(xiàn)Flex文件上傳功能,還真是很方便,這里和大家分享一下。

Flex上傳文件功能

寫(xiě)過(guò)很多文件上傳的功能,包括AJAX實(shí)現(xiàn)動(dòng)態(tài)監(jiān)控上傳進(jìn)度的,現(xiàn)在看到了實(shí)現(xiàn)Flex文件上傳功能,還真是很方便,沒(méi)什么好說(shuō)的,F(xiàn)lex上傳文件代碼:

upload.mxml

  1. <?xmlversionxmlversion="1.0"encoding="utf-8"?> 
  2. <mx:Applicationxmlns:mxmx:Applicationxmlns:mx=http://www.adobe.com/2006/mxml
  3. creationComplete="init()"layout="absolute"width="497"height="136"
  4. backgroundGradientAlphas="[1.0,1.0]"backgroundGradientColors="[#F2F8F8,#45E7E5]"> 
  5. <mx:Scriptsourcemx:Scriptsource="upload.as"></mx:Script> 
  6. <mx:Style> 
  7. .myfont{font-size:13pt}  
  8. </mx:Style> 
  9. <mx:Buttonxmx:Buttonx="10"y="95"label="上傳文件"click="pickfile()"styleName="myfont"/> 
  10. <mx:Labelxmx:Labelx="10"y="10"text="文件上傳"styleName="myfont"/> 
  11. <mx:ProgressBarxmx:ProgressBarx="10"y="40"width="457"themeColor="#F20D7A"minimum="0"
  12. mode="manual"maximum="100"id="progress1"label="當(dāng)前進(jìn)度:0%"styleName="myfont"fontWeight="normal"/> 
  13. <mx:Labelxmx:Labelx="146"y="98"width="321"id="lbProgress"styleName="myfont"textAlign="right"/> 
  14. </mx:Application> 
  15.  

 upload.as

  1. 1//ActionScriptfile  
  2. 2importflash.events.Event;  
  3. 3importflash.net.FileFilter;  
  4. 4importflash.net.FileReference;  
  5. 5privatevarfileRef:FileReference=newFileReference();  
  6. 6privatefunctioninit():void{  
  7. 7  
  8. 8}  
  9. 9  
  10. 10privatefunctionpickfile():void{  
  11. 11varimageTypes:FileFilter=newFileFilter("圖片(*.jpg,*.jpeg,*.gif,*.png)","*.jpg;*.jpeg;*.gif;*.png");  
  12. 12vartextTypes:FileFilter=newFileFilter("文本文件(*.txt","*.txt;");  
  13. 13varofficeType:FileFilter=newFileFilter("Office文件(*.doc,*.xls","*.doc;*.xls");  
  14. 14varanyType:FileFilter=newFileFilter("所有文件(*.*)","*.*");  
  15. 15varallTypes:Array=newArray(imageTypes,textTypes,officeType,anyType);  
  16. 16fileRef.addEventListener(Event.SELECT,selectHandler);  
  17. 17fileRef.addEventListener(Event.COMPLETE,completeHandler);  
  18. 18fileRef.addEventListener(ProgressEvent.PROGRESS,progressHandler);  
  19. 19fileRef.addEventListener("ioError",ioerrorHandler);  
  20. 20try{  
  21. 21varsuccess:Boolean=fileRef.browse(allTypes);  
  22. 22}catch(error:Error){  
  23. 23trace("Unabletobrowseforfiles."+error.toString());  
  24. 24}  
  25. 25}  
  26. 26privatefunctionioerrorHandler(event:Event):void{  
  27. 27trace("Unabletouploadfile."+event.toString());  
  28. 28}  
  29. 29privatefunctionprogressHandler(event:ProgressEvent):void{  
  30. 30lbProgress.text="已上傳"+(event.bytesLoaded/1024).toFixed(2)+"K,共"+(event.bytesTotal/1024).toFixed(2)+"K";  
  31. 31varproc:uint=event.bytesLoaded/event.bytesTotal*100;  
  32. 32progress1.setProgress(proc,100);  
  33. 33progress1.label="當(dāng)前進(jìn)度:"+""+proc+"%";  
  34. 34  
  35. 35}  
  36. 36privatefunctionselectHandler(event:Event):void{  
  37. 37varrequest:URLRequest=newURLRequest("http://localhost:9080/upload/upload.jsp")  
  38. 38try  
  39. 39{  
  40. 40fileRef.upload(request);  
  41. 41}  
  42. 42catch(error:Error)  
  43. 43{  
  44. 44trace("Unabletouploadfile."+error.toString());  
  45. 45}  
  46. 46}  
  47. 47privatefunctioncompleteHandler(event:Event):void{  
  48. 48trace("uploaded");  
  49. 49}  

Flex上傳文件效果圖:


【編輯推薦】

  1. 實(shí)例解析Flex字體的使用
  2. FlexBuilder4十大新特性閃亮登場(chǎng)
  3. 學(xué)習(xí)總結(jié) 在Flex中如何嵌入Flex字體
  4. 揭開(kāi)Flex正則表達(dá)式的神秘面紗
  5. FlexBuilder開(kāi)發(fā)方法及特點(diǎn)解析 

 

責(zé)任編輯:佚名 來(lái)源: cnblogs.com
相關(guān)推薦

2010-08-06 13:22:48

FlexCSS

2010-08-10 16:41:54

FlexJSP

2010-08-04 09:26:27

Flex數(shù)據(jù)

2010-07-27 10:39:25

Flex組件

2010-08-10 09:40:23

Flex與瀏覽器交互

2024-03-27 08:28:31

元素拖拽API文件上傳

2010-07-28 08:44:12

Flex2.0

2010-08-12 11:05:33

Flex數(shù)據(jù)綁定

2010-07-20 15:26:26

Perl文件

2010-07-30 13:08:38

Flex調(diào)用JavaS

2010-08-10 15:26:38

Flex應(yīng)用程序

2010-07-30 13:52:17

Flex組件

2009-11-16 14:15:51

PHP上傳多個(gè)文件

2010-08-09 10:34:05

Flex背景

2010-08-03 14:52:49

Flex界面設(shè)計(jì)

2010-07-30 09:28:09

Flex數(shù)據(jù)綁定

2010-08-05 15:46:13

Flex行為Flex效果

2009-11-16 13:04:04

PHP上傳文件代碼

2010-07-29 15:36:23

Flex安全沙箱

2010-07-29 13:18:45

Flex右鍵菜單
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)