- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- horizontalAlign="center"
- xmlns:ns1="module.*"
- width="800"
- verticalScrollPolicy="off" height="648.63635">
- <mx:Style>
- global {
- fontSize : 12;
- }
- </mx:Style>
- <mx:Script>
- <![CDATA[
- private var yourphotoname:String ;
- private var file:FileReference = new FileReference();
- [Bindable]
- private var stateText:String ;
- protected override function createChildren():void {
- super.createChildren();
- file.addEventListener(Event.SELECT, fileselectHandler);
- //file.addEventListener(Event.COMPLETE, file_complete);
- file.addEventListener(ProgressEvent.PROGRESS, fileprogressHandler);
- file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA ,uploadCompleteHandler) ;
- }
- /**************文件上传完成***************/
- private function uploadCompleteHandler(e:DataEvent):void{
- stateText = e.data ;
- imageeditID.photoURL = e.data ;
- tabbar1.selectedIndex = 1 ;
- //filenameID.text = "" ;
- }
- /**************文件上传完成***************/
- private function fileselectHandler (e:Event):void {
- filenameID.text = file.name;
- }
- /**************上传中***************/
- private function fileprogressHandler (e:ProgressEvent):void {
- stateText = Math.round(100 * e.bytesLoaded / e.bytesTotal) + "%";
- }
- /**************上传照片***************/
- private function upload ():void {
- if (file.size > 0) {
- var request:URLRequest = new URLRequest("http://localhost:8080/uploadservlet");
- file.upload(request);
- }
- }
- ]]>
- </mx:Script>
- <mx:TabBar id="tabbar1" dataProvider="viewstack1" width="760" height="30"/>
- <mx:ViewStack id="viewstack1" width="750" height="500">
- <mx:Canvas label="上传照片" width="100%" height="100%">
- <mx:Button x="140" y="10" label="浏览" click="file.browse();"/>
- <mx:TextInput id="filenameID" x="10" y="10" width="111"/>
- <mx:Button x="202" y="152" label="上传" width="78" click="upload();"/>
- <mx:Label x="10" y="154" text="{stateText}" id="ProgressID"/>
- </mx:Canvas>
- <ns1:imageEdit label="照片编辑" id="imageeditID" width="100%" height="100%">
- </ns1:imageEdit>
- </mx:ViewStack>
- </mx:Application>
flex 上传图片
最新推荐文章于 2021-02-19 03:27:01 发布