<? xml version = " 1.0 " encoding = " utf-8 " ?> < mx:Application xmlns:mx = " http://www.adobe.com/2006/mxml " layout = " absolute " width = " 294 " height = " 144 " usePreloader = " true " viewSourceURL = " srcview/index.html " > < mx:Button x = " 112 " y = " 23 " label = " 文件上载 " click = " UploadFile(); " /> < mx:ProgressBar id = " ProgressBar " labelPlacement = " bottom " themeColor = " #F20D7A " minimum = " 0 " visible = " true " maximum = " 100 " label = " 当前进度 " direction = " right " mode = " manual " width = " 200 " x = " 53 " y = " 67 " /> < mx:Label x = " 147 " y = " 81 " text = " Label " id = " ProgressLabel " /> < mx:Style > ProgressBar ... { barColor: #ff00cc; paddingLeft: 0; paddingRight: 3; textIndent: 0; letterSpacing: 0; trackHeight: 14; verticalGap: 0; fontSize: 12; fontWeight: normal;} </ mx:Style > < mx:Script > <! [CDATA[ import flash.events. * ; import mx.controls.Alert; import mx.events. * ; private var file:FileReference = new FileReference(); public function UploadFile(): void ... { file.addEventListener(Event.SELECT, onSelect); file.addEventListener(ProgressEvent.PROGRESS, onProgress); file.browse( [ new FileFilter("Images", "*.jpg;*.gif;*.png"), new FileFilter("Flash Movies", "*.swf") ] ); } private function onSelect(e:Event): void ... { Alert.show("确认上载?" + file.name + "共" + Math.round(file.size/(1024*1024)) + "M?", "文件上传", Alert.YES|Alert.NO, null, doUpload); } private function onProgress(e:ProgressEvent): void ... { ProgressLabel.text = "已上载"+ Math.round(e.bytesLoaded/1024) + "k 共计:"+ Math.round(e.bytesTotal/1024) +"k"; var proc:uint = e.bytesLoaded / e.bytesTotal *100; ProgressBar.setProgress(proc, 100); ProgressBar.label = "当前进度:"+ proc +"%"; } private function doUpload(e:CloseEvent): void ... { if(e.detail == Alert.YES)...{ var request:URLRequest = new URLRequest("http://wow.dgoo.net/test/upload.php"); try ...{ file.upload(request); } catch(e:Error)...{ trace("上载错误"); } } } ]] > </ mx:Script > </ mx:Application >