6 Replies Latest reply on Nov 16, 2008 10:05 AM by Rothrock

    preloader problem

    mkayyali Level 1

      i have a problem in my preloader, i have 2 scenes, first one the preloader and the another is the content of the site ( 10 frames )

      the preloader start showing the loader in 56% not from 0% so the user have to wait from 0% to 56% with blank stage.

      even though, if i used the same preload but in only 1 frame in the content scene its will work great.

      i don't load anything from external movies, all my content in one scene...

      Thanks a lot...
      my code:

        • 1. Re: preloader problem
          Rothrock Level 5
          Oh. You have so many things wrong with this project.

          First unless you are publishing to Flash 5 you shouldn't be using onClipEvents(). That was a style of coding that went out in 2001 when Flash 6 was introduced and has a lot of drawbacks and no advantages. (Well unless you need to publish to Flash 5!) Here is a really good blog on the issue:


          Okay the next issue is that you really shouldn't use scenes. They were a great tool to help timeline animators organize their content. But when you start to use code it starts to breakdown. There are several tricky little problems that crop up when you start using code that moves the playhead and scenes. So it is better to not put them on scenes. Instead just put your first "scene" on frame one. And then maybe move over to frame 100 and start your second "scene." When you publish your swf all the scenes are strung together in one long timeline and the "scenes" are gone per se.

          Next issue is the one you actually are asking about. All the content in frame 1 (the actual frame one after all the scenes are strung together) must be loaded before any code on that screen can start to execute.

          So if you have any components, even if they are only in the library and you aren't using them, will put a lot of content into frame 1. If you have a bunch of library assets set to export for actionscript those usually are in frame one as well.

          Otherwise, you can go to the publish settings and switch to the flash tab. There is a check box for generate a size report. When you publish you will also get a text file that shows you how much content is in your file and where it is.
          • 2. Re: preloader problem
            Ned Murphy Adobe Community Professional & MVP
            Do you declare the variables somewhere outside those functions?...

            var total: etc
            • 3. Re: preloader problem
              mkayyali Level 1
              Thanks Rothrock for the suggestions and the reference, i see it and i convert my code like what in the touts, so below is my final code.
              var total:Number;
              var loaded:Number;
              var percent:Number;

              progressBar.onEnterFrame = function():Void {
              total = _root.getBytesTotal();
              loaded = _root.getBytesLoaded();
              percent = int(loaded/total*100);
              progressBar.per = "loading "+percent+" %";
              if (loaded == total) {

              and now i put it in first frame before the sections frames ( now i have 11 frame in only One Scene , 10 for sections and 1 for loading )

              and it's also doesn't work, same problem start appear from 56%

              NedWebs, yes i declared the vars.

              Thanks a lot guys.

              • 4. Re: preloader problem
                Rothrock Level 5
                Well all those first things weren't things that would fix your problem. They were just suggestions on how to make better code that will help you move forward with your coding skills.

                Have you checked what is in frame 1? Do you have components in the Library, even if you aren't using them.

                My guess is that 56% of your file is in the first frame (whether you know it or not) and so it must all load before the code can start running.

                BTW, here is a little extra bit for your code.

                Sometimes on the first frame or so of a loading the bytesTotal and bytesLoaded can both be zero and therefore they are equal. That won't be a problem here, but it could be a problem if you reuse this code for loading some external file.

                Also. When you are done with your loader it is good practice to delete the onEnterFrame event. Why keep checking to see if everything is loaded after you know it is?

                So inside the conditional. Before the _root.play() you should add:

                delete progressBar.onEnterFrame;

                That will free up system resources.

                So look at your library for components, generate a size report and then post back with your findings.
                • 5. Re: preloader problem
                  mkayyali Level 1

                  Hey Rothrock,
                  i added the delete enterFrame. i use components but not in frame 2, i use in my file the following comps ( flv, uiScroll,MediaController, laoder and scrollPane ) .

                  in bandwidth Profile when test movie, size is :914574B but when trace the _root.getBytesTotal(); it told me its 1367671B !!! i dont know how.

                  about the size report the following is the result:

                  Frame # Frame Bytes Total Bytes Scene
                  ------- ----------- ----------- ----------------
                  1 513095 513095 Movie (AS 2.0 Classes Export Frame)
                  2 222355 735450
                  3 38654 774104
                  4 151 774255
                  5 68491 842746
                  6 345 843091
                  7 4282 847373
                  8 37026 884399
                  9 15395 899794
                  10 2969 902763
                  11 11691 914454


                  is there any advanced preloader to load all the movie include the frames and the components and everything in the movie :D

                  • 6. Re: preloader problem
                    Rothrock Level 5
                    Right so all those components regardless of where you use them need to be exported in frame 1. So that is making it so that 56% of your content does have to load before the code on the first frame can start running.

                    I think the size difference between the profiler and the getBytesTotal has something to do with the compression that Flash applies to the swf. In your preference you'll see a check box for compress movie. So in some cases Flash reports the whole uncompressed size of the swf and in others it reports the compressed size. At least I think that is what is going on. It is nothing to worry about.

                    Frame 1 must load before anything can happen. There is no way around that. The trick is to use two different swf files. That way you have two different frame 1s!

                    Make one swf that basically only has preloader code. Make another swf that is your content. Have the first one make an empty movie clip and load the second one into the clip. It is a good idea not to load the second one directly into the _root. It can be done, but I advise against it.

                    I you are going to make two swfs. Then you have some other things to look out for. First if you all kinds of calls to _root in your existing code they will fail in the two tier system. That is because _root is now the timeline of the original loader swf.

                    Also I would recommend using the MovieClipLoader class instead of the old-school style preloader you have here. Check it out in the help docs and if you want to go that way let me know if you have any questions.