9 Replies Latest reply on Jan 16, 2009 7:24 AM by kglad

    preloading images for xml slideshow

    Level 1
      i have created a xml based slideshow for flash 8 and need to preload all the images before it starts to play because i am getting large gaps between some of the images and it does not look to good. ideally there would be no gaps at all but the code works by loading one image which fades in and then it fades that out once that has gone it fades the next image in and so on.
      the code i have has been attached to the message. any help with this would be greatly appreciated.
        • 1. Re: preloading images for xml slideshow
          kglad Adobe Community Professional & MVP
          before you call randomImage() (from loadImages) load your images. when preloading is done, then call randomImage().
          • 2. Re: preloading images for xml slideshow
            Level 1
            so i should have all the preloading done here before the random image is called

            function loadImages(loaded) {
            if (loaded) {
            xmlFirstChild = this.firstChild;
            imageFileName = [];
            totalImages = xmlFirstChild.childNodes[0].childNodes.length;
            for (i=0; i<totalImages; i++) {
            imageFileName = xmlFirstChild.childNodes[0].childNodes.attributes.title;
            }
            //put the preloading images section in here
            //should all images be preloaded first.
            randomImage();
            }
            }


            should all the images be preloaded.
            • 3. Re: preloading images for xml slideshow
              kglad Adobe Community Professional & MVP
              yes, but you need to comment out randomImage() because loading is asynchronous: ie, even if you put your loadMovie() code above randomImage() that doesn't mean they images will load before randomImage() is called.

              so, call a function that loads are your images (instead of calling randomImage() and then when loading is complete, call randomImage().
              • 4. Re: preloading images for xml slideshow
                Level 1
                do you no of any code i can look at so i can see how i should go about doing this. i am still coming to grips with actionscripting i am still stuck on the learning curve for this.

                would i have to use MovieClipLoader to load all the images in to and then call the random image from there?
                • 5. Re: preloading images for xml slideshow
                  kglad Adobe Community Professional & MVP
                  you don't have to use the moviecliploader (mcl) class but you could use the mcl class and its onLoadInit() listener method to assure movieclips are loaded before starting your display.

                  or you could continue to use loadMovie() and preloader code (check the getBytesLoaded() and getBytesTotal() movieclip methods).
                  • 6. preloading images for xml slideshow
                    Level 1
                    can you tell i am still new to this. so if i stick with the loadMovie class would the code i need to add to make sure the image is loaded go after the loadMovie line of code.

                    i thought getBytesLoaded() and getBytesTotal() was only used when you wanted to show the user that something is being loaded.

                    just to make it clear i want the first image to display and with the code i have if i remember correctly it should stay on the screen for about 2 seconds. while this image is being displayed i want the next image to be geating preloaded and then display directly after the first. with the code i have the images are just loaded one after another so i end up with large gaps between some of the images with larger file sizes.
                    • 8. Re: preloading images for xml slideshow
                      Level 1
                      thanks for the reply on this i have been looking through the code you uploaded and it is making some sence to me. the more i use it the better i will become and the more i will understand.

                      the code works fine i have added a tween to the images coming on to the stage but i cannot get it to work when the images are leaving the stage. here is the code with the one line added for the tween
                      • 9. Re: preloading images for xml slideshow
                        kglad Adobe Community Professional & MVP
                        the tween is in the wrong location. you can't tween the target movieclip before loading is complete and expect the tween to be visible on-stage. place the tween in preloadF() when loading is complete. to prevent a momentary flash, you can assign the alpha of the target movieclip to be 25 when the load starts.