5 Replies Latest reply on Aug 11, 2009 9:22 AM by kglad

    Loading a series of images in sequence...

    stillLrng

      I'm trying to build a slideshow that has a lot of images, all broken apart into smaller sections, that I want to load sequentially so that while the first set of images scrolls across the stage the second set is loading, then the third, and so on.  I know this should be fairly easy, I'm just not sure how to get started the proper way.  Any help would be very much appreciated.

       

      Jeff

        • 1. Re: Loading a series of images in sequence...
          kglad Adobe Community Professional & MVP

          here's one way to do that:

           

          var imageA:Array=[array of images to be loaded];

           

          var mcl:MovieClipLoader=new MovieClipLoader();

          var lo:Object={};

          lo.onLoadInit=function(target:MovieClip){

          index++;

          if(index<imageA.length){

          loadF();

          } else {

          // loading is complete

          }

          }

          mcl.addListener(lo);

           

          var index:Number=0;

          loadF();

           

          function loadF(){

          var mc:MovieClip=createEmptyMovieClip("target_"+index,index);

          mcl.load(imageA[index],mc);

          }

          1 person found this helpful
          • 2. Re: Loading a series of images in sequence...
            stillLrng Level 1

            Thanks for the fast response.   Here's what I've came up with...   Would it be more efficient to use your version without the onEnterFrame's?  And also, what's the easiest way to specify image names in my array that are two or three folders deep.  (i.e.; tourPage/slideShow/img1.jpg)  Is there something I can add so I don't have to write the initial file path for each name in the array?

             

            Thanks again,

             

            Jeff

             

            Code:

             

            var images:Array = ["img1.jpg", "img2.jpg", "img3.jpg", "etc."];
            var targets:Array = ["holder1_mc", "holder2_mc", "holder3_mc", "etc."];

             

            var path:String;
            var holder:String;

             

            var loadNext = function():Void{
                    if(images.length > 0){
                            path = images.shift().toString();
                            holder = targets.shift().toString();
                            this[holder].loadMovie(path);
                            _root.onEnterFrame = function():Void{
                                    if(this[holder]._width){
                                            delete this.onEnterFrame;
                                            loadNext();
                                    }
                            }
                    }
            }
            loadNext();

            • 3. Re: Loading a series of images in sequence...
              kglad Adobe Community Professional & MVP

              1.  there's no difference in efficiency.

               

              2.  append the fixed part of the image paths in your loadMovie() line

               

              p.s.  don't use strings in targets or convert those strings to movieclips in loadNext()

              1 person found this helpful
              • 4. Re: Loading a series of images in sequence...
                stillLrng Level 1

                Here's the change to the path...  Not sure if that is correct?   Also, since I'm fairly new to using arrays and strings in the first place, how can I get rid of the string, and is it really necessary to have them at all in my situation?  I thought you had to use the toString(); to apply the next image to the path variable?

                 

                var images:Array = ["img1.jpg", "img2.jpg", "img3.jpg", "etc."];
                var targets:Array = ["holder1_mc", "holder2_mc", "holder3_mc", "etc."];

                 

                var path:String;
                var holder:String;

                 

                var loadNext = function():Void{
                        if(images.length > 0){
                                path = images.shift().toString();
                                holder = targets.shift().toString();
                                this[holder].loadMovie("tourPage/slideshow/"+path);
                                _root.onEnterFrame = function():Void{
                                        if(this[holder]._width){
                                                delete this.onEnterFrame;
                                                loadNext();
                                        }
                                }
                        }
                }
                loadNext();

                • 5. Re: Loading a series of images in sequence...
                  kglad Adobe Community Professional & MVP

                  you don't need to use toString() because those are already strings.