-
as3 pre loader
hi guys i have this pre-loader and it works fine but i have a feeling it is not 100%
Actionscript Code:
stop();
var preLoaderPercent:Number = 0;
addEventListener(Event.ENTER_FRAME, loadComplete); this.loaderInfo.addEventListener(Event.COMPLETE, loadComplete); this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
function loadComplete(e:Event):void { if (this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal) { removeEventListener(Event.ENTER_FRAME, loadComplete); this.loaderInfo.removeEventListener(Event.COMPLETE, loadComplete); this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, loadProgress); gotoAndPlay(2); } }
function loadProgress(e:ProgressEvent):void { preLoaderPercent = e.bytesLoaded / e.bytesTotal; percentLoader.percentText.text = Math.ceil(preLoaderPercent * 100) + "%"; }
i got it online but it just doesnt seem 100% is this good or is there something missing?
-
You don't need the enter frame stuff, and you don't need the if statement within loadComplete. You could move the stop() into loadProgress. Here's some code I've used in the past:
Code:
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
this.loaderInfo.addEventListener(Event.COMPLETE,doneLoading);
function showProgress(evt) {
stop();
var percentLoad=Math.round((evt.bytesLoaded/evt.bytesTotal)*100);
loadDisplay.text=percentLoad+"%";
}
function doneLoading(evt){
play();
this.loaderInfo.removeEventListener(Event.COMPLETE,doneLoading);
this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS,showProgress);
}
-
wow thank you i was wondering what that was doing there? thank you so much
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|