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

flex 学习笔记 filereference(三)

发布时间:2020-12-15 04:50:45 所属栏目:百科 来源:网络整理
导读:当FileReference的browse()选择好图片后,如何得到已选择图片的路径? 利用DataEvent.UPLOAD_COMPLETE_DATA,当上载文件成功且从服务器接收数据之后派发此事件。 代码如下: ? xml ? version = "1.0" ? encoding = "utf-8" ? ? s:Application ? xmlns:fx =

当FileReference的browse()选择好图片后,如何得到已选择图片的路径?

利用DataEvent.UPLOAD_COMPLETE_DATA,当上载文件成功且从服务器接收数据之后派发此事件。

代码如下:

 
 
  1. <?xml?version="1.0"?encoding="utf-8"?>?
  2. <s:Application?xmlns:fx="http://ns.adobe.com/mxml/2009"? ?
  3. ????????????????xmlns:s="library://ns.adobe.com/flex/spark"? ?
  4. ????????????????xmlns:mx="library://ns.adobe.com/flex/mx">?
  5. ????<fx:Script>?
  6. ????????<![CDATA[ ?
  7. ????????????public?var?file:FileReference; ?
  8. ???????????? ?
  9. ????????????public?function?selectFile():void? ?
  10. ????????????{ ?
  11. ????????????????file?=?new?FileReference(); ?
  12. ????????????????file.addEventListener(Event.SELECT,?fileSelected); ?
  13. ????????????????file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,?uploadDataComplete); ?
  14. ????????????????file.addEventListener(Event.COMPLETE,?uploadComplete); ?
  15. ????????????????file.addEventListener(IOErrorEvent.IO_ERROR,?handleError); ?
  16. ????????????????file.browse(); ?
  17. ????????????}???? ?
  18. ????????????public?function?handleError(event:IOErrorEvent):void? ?
  19. ????????????{ ?
  20. ????????????????status_txt.text?=?'ERROR:?'?+?event.text?+?''; ?
  21. ????????????} ?
  22. ????????????public?function?fileSelected(event:Event):void ?
  23. ????????????{ ?
  24. ????????????????file?=?FileReference(event.target); ?
  25. ????????????????file_txt.text?=?file.name; ?
  26. ????????????????status_txt.text?=?'upload?file:?'+?file.name?+?'';???????? ?
  27. ????????????????var?request:URLRequest?=?new?URLRequest(); ?
  28. ????????????????request.url?=?"http://cn-pc-hz2166:9080/UploadServlet"; ?
  29. ????????????????var?headerVariables:URLVariables?=?new?URLVariables(); ?
  30. ????????????????headerVariables.fileName?=?file.name; ?
  31. ????????????????request.data?=?headerVariables; ?
  32. ????????????????request.method?=?URLRequestMethod.POST; ?
  33. ????????????????file.upload(request,"Filedata");???????????? ?
  34. ????????????}???? ?
  35. ????????????public?function?uploadDataComplete(event:DataEvent):void? ?
  36. ????????????{ ?
  37. ????????????????var?result:XML?=?new?XML(event.data); ?
  38. ????????????????status_txt.text?+=?'Upload?Data?Complete' ?
  39. ????????????????status_txt.text?+=?'RESULT:?'?+?result.toString()?+?'' ?
  40. ????????????} ?
  41. ???????????? ?
  42. ????????????public?function?uploadComplete(event:Event):void? ?
  43. ????????????{ ?
  44. ????????????????status_txt.text?+=?'Upload?complete'; ?
  45. ???????????????? ?
  46. ????????????} ?
  47. ????????]]>?
  48. ????</fx:Script>?
  49. ????<mx:VBox>?
  50. ????????<mx:TextInput?id="file_txt"/>?
  51. ????????<mx:Button?id="select_btn"?label="select"?click="selectFile();"/>?
  52. ????????<mx:TextArea?id="status_txt"?width="400"?height="200"/>?
  53. ????</mx:VBox>?
  54. </s:Application>

(编辑:李大同)

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

    推荐文章
      热点阅读