Skip navigation
Currently Being Moderated

Preloader Not Working

Sep 24, 2012 1:49 AM

Tags: #not #bug #preloader #actionscript3 #loading #stopped

Hi guys, I'm having issues with my preloader and I simply cannot see the issue with it. It's the exact same code I've been using for all my previous projects and yet it's suddenly stopped working. Hoping a fresh set of eyes will be able to spot the problem. The code appears to run fine when I am debugging my game (CMD + Return) but if I run the swf file in Flash (using simulate download) to test the loading bar it doesn't move at all, just sits at the lowest point even though the game is in fact loading. In my settings everything (except the preloader) is set to export in frame 2, my preloader is in frame 1, and the "afterItemsLoaded" label takes you to frame 3.

 

Here's an extract of the the document class (that calls the preloader):

 

public dynamic class Engine extends MovieClip

    {

        private var _preloader:Preloader;

 

        private var _gameLayer:MovieClip;

 

        private var _mainMenu:MainMenu;

 

        public function Engine()

        {

            trace("Starting up Engine");

 

            this.focusRect = false;

            addEventListener(Event.ADDED_TO_STAGE, startEverything);

        }

 

 

        private function startEverything(e:Event):void

        {

            removeEventListener(Event.ADDED_TO_STAGE, startEverything);

 

            var isOnCorrectSite:Boolean = checkURL();

 

            trace("isOnCorrectSite = " + isOnCorrectSite.toString());

 

            if(isOnCorrectSite)

            {

                _preloader = myPreloader;

                _preloader.begin(this.loaderInfo);

                _preloader.addEventListener("loadComplete", loadAssets);

                _preloader.addEventListener("preloaderFinished", loadComplete);                   

            }

            else

            {

                gotoAndStop(1);

 

                myPreloader.alpha = 0;

            }

 

        }

}

 

I think that's all the important bits from that, and the preloader code is:

 

public class Preloader extends MovieClip

    {

 

        public var _ldrInfo:LoaderInfo;

 

        public function Preloader():void

        {

            trace("New preloader created");

        }

 

 

        public function begin(ldrInfo:LoaderInfo = null):void

        {

            trace("Beginning load");

            this._ldrInfo = ldrInfo;

 

            addEventListener(Event.ENTER_FRAME, checkLoad);

        }

 

 

        private function checkLoad(e:Event):void

        {

            if (_ldrInfo.bytesLoaded == _ldrInfo.bytesTotal && _ldrInfo.bytesTotal != 0)

            {

                //loading complete

                trace("Load complete");

                dispatchEvent(new Event("loadComplete"));

                phaseOut();

            }

 

            updateLoader(Math.floor(_ldrInfo.bytesLoaded / _ldrInfo.bytesTotal));

        }

 

 

        private function updateLoader(num:uint):void

        {

            //num is a number between 0 and 1

            //e.g. mcPreloaderBar.width = num * fullWidth;

 

            this.loadBar.width = 10 + 290*num;

            trace("Updating loader, num: " + num + " so width will be: " + this.loadBar.width);

        }

 

 

        private function phaseOut() : void

        {

            trace("phaseOut called");

            removeEventListener(Event.ENTER_FRAME, checkLoad);

            phaseComplete();

        }

 

 

        private function phaseComplete() : void

        {

            trace("phaseComplete called");

            dispatchEvent(new Event("preloaderFinished"));

        }

 

    }

 

"New Preloader created" and "Beginning load" appear in the output, but nothing after that :/

 
Replies
  • kglad
    62,058 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 24, 2012 6:51 AM   in reply to Dinkyfish

    why aren't you seeing the traces from your Engine class?  is it exporting after frame 1?  if so, that's a problem.

     
    |
    Mark as:
  • kglad
    62,058 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 24, 2012 7:06 AM   in reply to Dinkyfish

    and??

     

    is var isOnCorrectSite:Boolean = checkURL();

     

    true?

     
    |
    Mark as:
  • kglad
    62,058 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 24, 2012 7:17 AM   in reply to Dinkyfish

    what are the first few (or the final, if the output remains the same) trace output lines using:

     

        private function checkLoad(e:Event):void

            {

    trace(_ldrInfo.bytesLoaded,_ldrInfo.byteTotal);

                if (_ldrInfo.bytesLoaded == _ldrInfo.bytesTotal && _ldrInfo.bytesTotal != 0)

                {

                    //loading complete

                    trace("Load complete");

                    dispatchEvent(new Event("loadComplete"));

                    phaseOut();

                }

     
    |
    Mark as:
  • kglad
    62,058 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 24, 2012 7:44 AM   in reply to Dinkyfish

    upload your files and test on a server.

     
    |
    Mark as:
  • kglad
    62,058 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 24, 2012 11:24 AM   in reply to Dinkyfish

    what's the trace output from:

     

    public function begin(ldrInfo:LoaderInfo = null):void

            {

                trace("Beginning load");

                this._ldrInfo = ldrInfo;

    var t:Timer=new Timer(1000,10);

    t.addEventListener(TimerEvent.TIMER,traceF);  // <- import the timer (flash.utils) and timerevent (flash.events)

                addEventListener(Event.ENTER_FRAME, checkLoad);

    trace("added",this.hasEventListener(Event.ENTER_FRAME));

            }

     

    private function traceF(e:TimerEvent):void{

    trace(this.hasEventListener(Event.ENTER_FRAME));

    }

     
    |
    Mark as:
  • kglad
    62,058 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 24, 2012 11:49 AM   in reply to Dinkyfish

    change:

     

    trace("Beginning load");

     

    to

     

     

    trace("new B load");

     

    to confirm you're editing the same class file that flash is using.

     
    |
    Mark as:
  • kglad
    62,058 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 24, 2012 1:39 PM   in reply to Dinkyfish

    zip your assets upload them and post a link.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points