9 Replies Latest reply on Jun 19, 2007 9:47 AM by Newsgroup_User

    preloading external images

    saz_
      I've looked at many tutorials on preloading external images and followed them to set up a basic scene with just a preloader and 9 external swf files. The problem I have is that the movies start playing before the preloader has got to 100%. ie its not waiting for the preloader to finish before starting the movie.

      So from what I can work out the preloader is working and the link to the external files and movie clip is working but for some reason they are not communicating with each other.

      Any ideas. Im not sure if its the script on the 2nd frame of the main scene

      if (this.getBytesTotal()>=this.getBytesTotal()) {
      gotoAndStop(3);
      } else {
      gotoAndPlay(1);
      }
        • 1. Re: preloading external images
          Level 7
          saz_,

          > I've looked at many tutorials on preloading external
          > images and followed them to set up a basic scene with
          > just a preloader and 9 external swf files.

          Okay.

          > The problem I have is that the movies start playing
          > before the preloader has got to 100%.

          Looking at your code sample, I see that you're checking the
          MovieClip.getBytesTotal() method against a "this" reference, which is fine
          ... but it means you're checking against whatever "this" points to. If this
          code is in the main timeline, then "this" points to the main timeline.
          You're preloading the main SWF itself this way, but not any of the 9
          external SWFs. Does that make sense? You would need to check the bytes
          loaded and total of each of those, too.

          In addition ...

          > if (this.getBytesTotal()>=this.getBytesTotal()) {

          ... you're checking bytes total against bytes total. Should be bytes
          *loaded* against bytes total.


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. preloading external images
            Greg Dove Level 4
            This code is for preloading the main timeline, where all your activity and code starts from frame 3.
            In addition there is an error in the first line

            it should be:
            if (this.getBytesLoaded()>=this.getBytesTotal()) {

            If you have swfs that are loaded externally, then they will need their own 'preloaders' or a stop() command on their first frame (with control from the loading timeline to play when required)



            • 3. Re: preloading external images
              saz_ Level 1
              Thanks for the responses. Thats makes sense so I am now looking into another bit of the script which I now think has the error. which is pasted below. The play movie function is on the 5th frame of the preloaderloader. On the 3rd frame the script has the getBytesTotal line and if they are not equal it is told to go back. to the previous frame and load again But as I say, the preloader and the movie play similtaneously on each of the movie files rather than the preloader adn then the movie.

              var NumberOfImages = 9;
              var LocationToImages = "images/";
              var FileType = ".swf";
              var x = 0;
              var MyArray = new Array();
              var MyArray2 = new Array();;
              var i = 0;

              while (i<=NumberOfImages) {

              MyArray = LocationToImages+i+FileType;
              i++;
              }

              _global.Next = function() {

              _root.ButtonNext.enabled = false;
              _root.ButtonPrev.enabled = false;

              x = x+1;
              if (x<=NumberOfImages) {

              loadMovie(MyArray[x], _root.MyImagesHolder);

              if(MyArray2[x] == 1){

              _root.preloaderloader.gotoAndPlay(4);

              } else {

              MyArray2[x] = 1;

              _root.preloaderloader.gotoAndPlay(2);
              }

              } else {

              x = NumberOfImages;

              _root.ButtonPrev.enabled = true;

              }
              };

              _global.Previous = function() {

              _root.ButtonNext.enabled = false;
              _root.ButtonPrev.enabled = false;

              MessageDisplay = "";
              x = x-1;

              if (x>=0) {

              loadMovie(MyArray[x], _root.MyImagesHolder);

              _root.preloaderloader.gotoAndPlay(4);

              } else {

              _root.ButtonNext.enabled = true;

              }
              };

              _root.ButtonNext.enabled = false;
              _root.ButtonPrev.enabled = false;

              stop();
              • 4. Re: preloading external images
                Greg Dove Level 4
                sorry David... I'll let you continue... There was a slight delay before your post arrived on the web forum , so I hadn't seen your reply yet when I posted - but you answered before me in terms of when you submitted your original reply.

                • 5. Re: preloading external images
                  Level 7
                  saz_,

                  > The play movie function is on the 5th frame of the
                  > preloaderloader. On the 3rd frame the script has
                  > the getBytesTotal line and if they are not equal it is
                  > told to go back

                  This sounds to me like you're using a movie clip to act as your
                  preloader, relying on frame loops in that movie clip to manage your various
                  loadings. This sort of thing can be made to work just fine, but it can also
                  lead to something of a complicated sprawl of code.

                  Have you looked into the MovieClipLoader class, at all? Rather than
                  looping among frames, to repeatedly check for loaded bytes, you can
                  instantiate that class and handle its dispatched events to do the same
                  thing(s) and more.


                  David Stiller
                  Adobe Community Expert
                  Dev blog, http://www.quip.net/blog/
                  "Luck is the residue of good design."


                  • 6. Re: preloading external images
                    Level 7
                    GWD,

                    > sorry David... I'll let you continue...

                    No worries! :) More input can be a good thing.

                    > There was a slight delay before your post arrived on the
                    > web forum , so I hadn't seen your reply yet when I posted -

                    That happens a lot when NNTP and Web posts combine. I've already
                    recommended the MovieClipLoader class for saz_, mainly because I think it
                    will ultimately be less dicey in terms of so many frame loops for so many
                    external files.


                    David Stiller
                    Adobe Community Expert
                    Dev blog, http://www.quip.net/blog/
                    "Luck is the residue of good design."


                    • 7. Re: preloading external images
                      saz_ Level 1
                      Thanks for you help, will look at that class now.

                      Thanks again
                      • 8. Re: preloading external images
                        saz_ Level 1
                        MovieClipLoader class isn't the answer as I am working with Flash mx and after following 5 different tutorials none of them work.

                        Guessing I need to continue with the preloader tutorials and loops but still have the issue of the movie clip and the prelaoder running simultaneously
                        • 9. Re: preloading external images
                          Level 7
                          saz_,

                          > MovieClipLoader class isn't the answer as I am working with
                          > Flash mx and after following 5 different tutorials none of them
                          > work.

                          Shucks! MovieClipLoader was introduced in Flash MX 2004 for Flash
                          Player 7. Well, loops it is, then.

                          > Guessing I need to continue with the preloader tutorials and
                          > loops but still have the issue of the movie clip and the prelaoder
                          > running simultaneously

                          I'm afraid I can't tell, from what I've ready so far, how the preloader
                          movie clip is related to your various loads. You *could* do all these loads
                          from the main timeline. I *think* you're using the timeline of a preloader
                          movie clip for some of these, and that's where I lose track of what you're
                          doing.

                          If you reason it out, though, the concept is straightforward enough:
                          movie clips load SWFs and images. Movie clips also let you know how many
                          bytes they've loaded. Movie clips *also* happen to dispatch an onEnterFrame
                          event, which lets you use them to repeatedly check those values. It may
                          help you to spread out your various loads among a handful of frames each on
                          the main timeline (though it's certainly possible to do them all at once).


                          David Stiller
                          Adobe Community Expert
                          Dev blog, http://www.quip.net/blog/
                          "Luck is the residue of good design."