由于主管急着使用,以解燃眉之急,暂时为留出更多接口,待稍后修改再奉上。
package { import flash.display.Sprite; import flash.net.URLLoader; import flash.net.URLRequest; import flash.events.Event; import flash.events.ProgressEvent; public class URLLoaderBar extends Sprite { private var urlLoader:URLLoader; private var loaded:Sprite;//loaded UI private var total:Sprite;//total UI public function URLLoaderBar(urlRequest:URLRequest) { //draw total bar; total.graphics.beginFill(0x000000,1); total.graphics.drawRect(0,0,200,10); total.graphics.endFill(); total.x = total.y = 0; this.addChild(total); //draw loaded bar; loaded.graphics.beginFill(0x00ff00,1); loaded.graphics.drawRect(0,0,0,10); loaded.graphics.endFill(); loaded.x = total.y = 0; this.addChild(loaded); //start to listen urlLoader = new URLLoader(urlRequest); urlLoader.addEventListener(Event.OPEN, onOpenHandler); urlLoader.addEventListener(ProgressEvent.PROGRESS, onProgressHandler); urlLoader.addEventListener(Event.COMPLETE, onCompleteHandler); } private function onOpenHandler(event:Event):void{ trace('opened'+ urlLoader.bytesLoaded+'%') } private function onProgressHandler(event:ProgressEvent):void{ var amount:Number = (urlLoader.bytesLoaded/urlLoader.bytesTotal)*200; loaded.graphics.clear(); loaded.graphics.beginFill(0x00ff00,1); loaded.graphics.drawRect(0,0,amount,10); loaded.graphics.endFill(); } private function onCompleteHandler(event:Event):void{ trace('load complete'+ urlLoader.bytesLoaded+'%') } }}