package { import flash.display. MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.events.ProgressEvent; import flash.net.URLLoader; import flash.net.URLRequest; import flash.text.TextField; public class Main extends Sprite { var xmlUrl:URLRequest = new URLRequest("http://cidian.youdao.com/download/YoudaoDict.exe"); var xmlLoader:URLLoader = new URLLoader(xmlUrl); var txt:TextField = new TextField(); public function Main():void { init(); } private function init():void { // 资源正在加载 xmlLoader.addEventListener(ProgressEvent.PROGRESS, progressHanlder); // 若资源加载完成 xmlLoader.addEventListener(Event.COMPLETE, completeHandler); txt.width = 300; this.addChild(txt); } private function progressHanlder(event:ProgressEvent):void { // 已加载的字节数 var movieBytesLoaded:int = xmlLoader.bytesLoaded; var movieKLoaded:int = movieBytesLoaded / 1024; // 加载对象的总字节数 var movieBytesTotal:int = xmlLoader.bytesTotal; var movieKTotal:int = movieBytesTotal / 1024; txt.text = "已加载:" + movieKLoaded + "KB / 总大小:" + movieKTotal + "KB"; } private function completeHandler(event:Event):void { trace("资源加载完成!"); } } }