5 Replies Latest reply on Oct 1, 2009 7:49 AM by Ned Murphy

    Preload order from array

    AESS1981 Level 1

      I am preloading external swfs into my mc using:

       

      var externalSWFs:Array = ["1.swf", "2.swf", "3.swf", "4.swf", "5.swf", "6.swf"];

       

      function loadNextSWF() {

      if (index<externalSWFs.length) {

      loadTarget[index].loadMovie(externalSWFs[index]);

      preLoader.onEnterFrame = preloadF;

      } else {

      delete preLoader.onEnterFrame;

      }

      }

      function preloadF() {

      var bl:Number = loadTarget[index].getBytesLoaded();

      var bt:Number = loadTarget[index].getBytesTotal();

      if (bl>0 && bl>=bt) {

      index++;

      loadNextSWF();

      }

      }

       

      The swfs preload sequentially from 1 to 6, and the sequence always starts at '1.swf', as per the array order.

       

      Is there any way that if the user jumps to '3.swf', the first image that would preload in the array would be '4.swf' (then '5.swf', '6.swf', '1.swf', '2.swf')...

       

       

       

      Thanks!

        • 1. Re: Preload order from array
          Ned Murphy Adobe Community Professional & MVP

          It's not clear whether you have a problem or a desire to have something work a certain way.  Why would you want to have 4 loaded if the user jumped to 3?  What do you use to kick off running the loading?

           

          If your desire is to reorder the array, then look into the various methods that support the Array class, such as shift, splice, concat, and push, which you can use to remove and add items to an array.

          • 2. Re: Preload order from array
            AESS1981 Level 1

            Hi Ned, apologies if unclear.

             

            External swfs preload in the order 1, 2, 3, 4 ...

            Via a specific navigation route, the image '3.swf' is loaded first instead of '1.swf'. This is achieved by changing the pIndex value, using function:

             

            MovieClip.prototype.menuThree = function(d) {

            pIndex = (pIndex=2)%pArray.length;

            onEnterFrame = fadeOut;

            };

             

             

            Once this function is called, the following re-starts the preload sequence:

             

            MovieClip.prototype.fadeOut = function() {

            if (image_holder._alpha>fadeSpeed) {

            image_holder._alpha -= fadeSpeed;

            } else {

            loadPhoto();

            loadNextSWF();

            }

            };

             

            The function loadNextSWF() always load the 1st swf from the array. If '3.swf' loads first, it would be advantageous if the next preloaded image was '4.swf' to remain in the sequence order.

             

            Hope this makes sense

            Thanks

            • 3. Re: Preload order from array
              Ned Murphy Adobe Community Professional & MVP

              You can either rearrange the order of the array and keep incrementing index to work your way thru it, or you can shift the index value and somehow keep track that you skipped values and have to go back to it being 1 again to catch them.  I think the first approach would be the less complicated to sort out.  Just use a couple of the methods I mentioned earlier to take pieces off the front end of the array and add them onto the other end.

              • 4. Re: Preload order from array
                AESS1981 Level 1

                I'll look into it - thanks for the avice.

                • 5. Re: Preload order from array
                  Ned Murphy Adobe Community Professional & MVP

                  You're welcome