15 Replies Latest reply on Nov 15, 2010 2:55 PM by pwpau

    CS5, AS3 - Preloader

    Waggiesmacky

      I've been searching for guides/tutorials, basically any sort of help in making a preloader for a game. Also looked through previous posts on this forum.

      Whenever I have a preloader made without any errors and I click test movie (ctrl-enter), it skips the preloader and goes straight to my game's menuscreen. Fair enough, so I click simulate download, the window turns white, after that it turns grey with 3 or 4 dots blinking, as if it were a preloader, except not mine, after a while it goes into my games menuscreen again, completely bypassing the preloader.

       

      A walkthrough for a simple preloader (just a percentage going from 0 to 100), some code I can copy-paste, anything to make it work, I've tried all I can think of.

       

      /beg for help.

        • 1. Re: CS5, AS3 - Preloader
          kglad Adobe Community Professional & MVP

          do you have a lot of data (like sounds) exported for use by actionscript?  if yes, you will probably want to use an external preloader that will load your game.

           

          if no, copy and paste your current preloader code that should be in frame 1 of your main timeline with nothing on-stage but the preloader display.

          • 2. Re: CS5, AS3 - Preloader
            Waggiesmacky Level 1

            Small game so far, haven't even gotten as far as to the sounds yet.

             

            stop();

             

            import flash.events.ProgressEvent;
            import flash.events.Event;

            this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoading);
            this.loaderInfo.addEventListener(Event.COMPLETE, onComplete);

             

            function onLoading(evt:ProgressEvent):void {
                var loaded:Number = evt.bytesLoaded / evt.bytesTotal;
                loadbarText.text = "LOADING: " + (loaded*100).toFixed(0) + "%";
            };

             

            function onComplete(event:Event):void {
                this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, onLoading);
                this.loaderInfo.removeEventListener(Event.COMPLETE, onComplete);
                loadbarText.visible = false;
                gotoAndPlay(2);
            };

             

            That's my most recent code, found it in another post here, works for others...

            I've got a dynamic textfield called 'loadbarText' on-stage, nothing else. If I insert numbers into the textfield, it'll make them flash, never getting to my game though.

            This does as I explained before when simulating a download - white screen -> grey screen with the dots -> my menuscreen.

            • 3. Re: CS5, AS3 - Preloader
              kglad Adobe Community Professional & MVP

              that code's in frame 1 of your main timeline, correct?  if yes, copy the trace output using the following and paste it here:

               


               

              stop();

              trace(this.currentFrame,this);

               

              import flash.events.ProgressEvent;
              import flash.events.Event;

              this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoading);
              this.loaderInfo.addEventListener(Event.COMPLETE, onComplete);

               

              function onLoading(evt:ProgressEvent):void {
                  var loaded:Number = evt.bytesLoaded / evt.bytesTotal;
                  loadbarText.text = "LOADING: " + (loaded*100).toFixed(0) + "%";

              trace(loadbarText.text);
              };

               

              function onComplete(event:Event):void {
                  this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, onLoading);
                  this.loaderInfo.removeEventListener(Event.COMPLETE, onComplete);
                  loadbarText.visible = false;
                  gotoAndPlay(2);
              };

               


              • 4. Re: CS5, AS3 - Preloader
                Waggiesmacky Level 1

                Sorry, it was way past midnight here, went to sleep.

                Yes it is the code in frame 1 of the main timeline (code is in the "Actions" window).

                 

                trace(this.currentFrame,this); outputs:

                1 [object DocumentClass]
                1 [object DocumentClass]

                 

                But trace(loadbarText.text); doesn't return any output.

                • 5. Re: CS5, AS3 - Preloader
                  kglad Adobe Community Professional & MVP

                  you have code in frame 2 (or beyond) that's directing your timeline back to frame 1.


                  1 person found this helpful
                  • 6. Re: CS5, AS3 - Preloader
                    Waggiesmacky Level 1

                    I'm sure I don't. I wouldn't have a use for it, before I added the preloader, there only was one frame. I've even checked all my code to see, but there's nothing doing anything with frames.

                    • 7. Re: CS5, AS3 - Preloader
                      kglad Adobe Community Professional & MVP

                      make a test file using the code you showed, your preloader and with no code in frame 2.  retest.  any problem?

                      • 8. Re: CS5, AS3 - Preloader
                        Waggiesmacky Level 1

                        I included your traces, the output was:

                        1 [object MainTimeline]
                        LOADING: 100%
                        1 [object MainTimeline]

                         

                        But it still only shows a white screen, then switches to the stage colour afterwards; when it's loaded, I presume.

                        • 9. Re: CS5, AS3 - Preloader
                          kglad Adobe Community Professional & MVP

                          that confirms you're playing frame 1 more than once.

                           

                          no progressevent and no complete event is dispatched the 2nd time so you sit on frame 1.  fix your original file.

                          1 person found this helpful
                          • 10. Re: CS5, AS3 - Preloader
                            Waggiesmacky Level 1

                            Can you explain why it's showing a white screen instead of the preloader too?

                            • 11. Re: CS5, AS3 - Preloader
                              kglad Adobe Community Professional & MVP

                              because you set the preloader's visible property to false.

                              • 12. Re: CS5, AS3 - Preloader
                                Waggiesmacky Level 1

                                But that's only after it has loaded, I never see the preloader text.

                                • 13. Re: CS5, AS3 - Preloader
                                  kglad Adobe Community Professional & MVP

                                  how large is your swf?

                                   

                                  if it's a few hundred kb or larger upload to a server and test.  any problem (other than the return to frame 1), post a link to your url.

                                  • 14. Re: CS5, AS3 - Preloader
                                    Waggiesmacky Level 1

                                    Thanks alot, that worked

                                    • 15. Re: CS5, AS3 - Preloader
                                      pwpau

                                      could you please put up the final working code and a full description of how to get it working please for later reference by other people.

                                       

                                      Thanks