flex 上传文件预览
as文件: //文件浏览上传 import flash.net.FileFilter; import flash.net.FileReference; privatevar file:FileReference=new FileReference(); privatevar file2:FileReference=new FileReference(); privatevar file3:FileReference=new FileReference(); privatevar file4:FileReference=new FileReference(); ? privatefunction look(str:String):void { ??? //localChoose.addEventListener(MouseEvent.CLICK,doSelect); ??? //选择要上传文件的类型 ??? 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); ??? file.browse(allTypes); ??? file.addEventListener(Event.SELECT,onSelect); ? //submitBtn.addEventListener(MouseEvent.CLICK,doUpload); ? } ? ? privatefunction look2(str:String):void { ??? //localChoose.addEventListener(MouseEvent.CLICK, "*.jpg; *.jpeg; *.gif; *.png"); ??? var allTypes:Array=new Array(imageTypes); ??? file2.browse(allTypes); ??? file2.addEventListener(Event.SELECT,onSelect02); ? ?? //submitBtn.addEventListener(MouseEvent.CLICK,doUpload); ? } privatefunction look3(str:String):void { ??? //localChoose.addEventListener(MouseEvent.CLICK,doSelect); ??? //选择要上传文件的类型 ??? var officeType:FileFilter=new FileFilter("Office文件(*.doc,"*.doc; *.xls"); ??? var allTypes:Array=new Array(officeType); ??? file3.browse(allTypes); ??? file3.addEventListener(Event.SELECT,onSelect03); ? ?? //submitBtn.addEventListener(MouseEvent.CLICK,doUpload); ? } privatefunction look4(str:String):void { ??? //localChoose.addEventListener(MouseEvent.CLICK,doSelect); ??? //选择要上传文件的类型 ??? var anyType:FileFilter=new FileFilter("所有文件(*.*)","*.*"); ??? var allTypes:Array=new Array(anyType); ??? file4.browse(allTypes); ??? file4.addEventListener(Event.SELECT,onSelect04); ? ?? //submitBtn.addEventListener(MouseEvent.CLICK,doUpload); ? } publicfunction onSelect(evt:Event):void { ? ??? localPath01.text=file.name; } publicfunction onSelect02(evt:Event):void { ??? localPath02.text=file2.name; } publicfunction onSelect03(evt:Event):void { ??? localPath03.text=file3.name; } publicfunction onSelect04(evt:Event):void { ??? localPath04.text=file4.name; } publicfunction doUpload(event:Event):void { ??? if (localPath01.text =='') ??? { ??? ??? Alert.okLabel="确定"; ??? ??? Alert.show("请选择要上传的文件!","警告"); ??? } ??? else ??? { ??? ??? Alert.show("上传成功"); ??? } ? } ? mxml文件: ??? <mx:FormItem label="附件:"> ?????????? ?????? ??? <mx:HBox> ?????????? ?????????? ??? <mx:TextInput width="500" ?????????? ?????????? ?????????? ??? ? height="80" ?????????? ?????????? ?????????? ??? ? id="localPath04"/> ?????????? ?????????? ??? <mx:Button label="浏览..." ?????????? ?????????? ?????????? ?? click="look4('04')"/> ?????????? ?????? ??? </mx:HBox> ?????????? ??? ??? </mx:FormItem> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |