A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: as3 pre loader

  1. #1
    Member
    Join Date
    Feb 2010
    Posts
    32

    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?

  2. #2
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    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);
    }

  3. #3
    Member
    Join Date
    Feb 2010
    Posts
    32
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center