flash - How to use loaderInfo? -
i want make loading bar @ first need have loading info per enter frame. how seem not working. teach me how it?
var maploader : loader = new loader( ); var maploaderinfoload:number; var maploaderinfototal:number; public function engine() { addeventlistener( event.enter_frame, onenterframe,false,0,true ); maploader.load( new urlrequest( "mapcontrol.swf" ) ); maploader.contentloaderinfo.addeventlistener(event.complete, completehandler ); } private function onenterframe( evt:event ):void {maploaderinfoload = maploader.loaderinfo.bytesloaded; maploaderinfototal = maploader.loaderinfo.bytestotal; trace(maploaderinfoload); trace(maploaderinfototal);} public function completehandler ( eventobj : event ) : void { stage.addchild( maploader.content ); }
the bytestotal of loader's loaderinfo return 0 until loader has fired it's first progress
event. there reason why want use enterframe in way rather progress event?
simple progress event example:
var maploader : loader = new loader(); var maploaderinfoload:number; var maploaderinfototal:number; public function engine() { maploader.contentloaderinfo.addeventlistener(event.complete, completehandler ); maploader.contentloaderinfo.addeventlistener(progressevent.progress, progresshandler); maploader.load( new urlrequest( "mapcontrol.swf" ) ); } private function progresshandler(evt:progressevent):void { maploaderinfoload = evt.bytesloaded; maploaderinfototal = evt.bytestotal; trace(maploaderinfoload); trace(maploaderinfototal); }
enter frame
of course, there might reason use enterframe event. still in example, let progresshandler example populate variables; or wait until first progress event fired, delete progress event listener , add enterframe listener instead. long don't try read maploader.loaderinfo.bytestotal
before first progress event fired should ok.
Comments
Post a Comment