4 Replies Latest reply on Jul 21, 2013 6:18 PM by JonnyDL

    detect load completion from an array of images

    JonnyDL Level 1

      I have an array with 6 items. I have a for loop that dynamically builds a movie clip and loads the images. I'm trying to get an action/function to start only when the last image is finished loading I have the onLoadComplete working, but I cant seem to figure out how to get it to work on the last image and then activate an action/function?

      Wil I need to find another way of looping them using the onloadcomplete as a singnal to load the on image and then the other?

       

      Can anybody help?

        • 1. Re: detect load completion from an array of images
          kglad Adobe Community Professional & MVP

          you can use a variable to count the number of loaded images if you don't want to load them sequentially:

           

           

          var imagesLoaded:Number=0;

          whateverLO.onLoadComplete=function(mc:MovieClip){

          imagesLoaded++;

          if(imagesLoaded==yourarray.length){

          callyourfunction();

          }

          }

          • 2. Re: detect load completion from an array of images
            JonnyDL Level 1

            Thank you Kglad! I was able to get the script working. If I could bother you with a minor problem with the script? its with the depths. I had better controll over depths in AS3, but I need to write in AS2. Any way with the script, before I added the tweens I was able to stack the images one ontop of the other, and then set the depth of the banner_mc above the images, but when I go to tween them they are infront of the banner. How can I get that banner on top (of everything else)?

             

            import mx.transitions.Tween;

            import mx.transitions.easing.*;

             

             

            var MCL:Number

            var listener:Object = new Object()

            napolpics = new Array()

            napolpics = [

                                           "estimates_1_sm.jpg",

                                           "directions_1_sm.jpg",

                                           "partners_3_sm.jpg",

                                           "home_4_lg.jpg",

                                           "estimates_2_sm.jpg",

                                           "about_4_lg.jpg"

                                          ]

            MC_Tween = new Array

            MC_Tween = []

             

             

             

             

            for (var i=0; i < napolpics.length; i++)

             

             

            {

                      var imagesLoaded:Number=0;

             

             

                      var container:MovieClip = this.createEmptyMovieClip("big_"+i, this.getNextHighestDepth());

                      MC_Tween.push(container);

                      var mcLoader:MovieClipLoader = new MovieClipLoader();

                      mcLoader.addListener(this);

                      mcLoader.loadClip(napolpics[i], container);

                      container._y=75;

                      container._x=10;

                      container.height=161;

                      container.width=194;

             

                      this.onLoadComplete = function(mc:MovieClip)

                                {

                                          imagesLoaded++;

                                          if(imagesLoaded==napolpics.length)

                                          {

                                                    var tweenit=setTimeout(callyourfunction, 3000);

                                                    MCL= MC_Tween.length-1

                                          }

                                }

            }

             

             

            function TweenImages()

            {

                      trace (MCL)

                      var fadeit = new Tween(MC_Tween[MCL], "_X", Strong.easeInOut, MC_Tween[MCL]._x, 300, 4, true);

                      fadeit.onMotionFinished=function()

                      {

                                MCL--

                                if(MCL>-1){var tweenit=setTimeout(TweenImages, 3000);}

                                else{clearTimeout(tweenit)}

                      }

             

            };

            • 3. Re: detect load completion from an array of images
              kglad Adobe Community Professional & MVP

              assign your banner's depth to be napolpics.length

              1 person found this helpful
              • 4. Re: detect load completion from an array of images
                JonnyDL Level 1

                thanks...that confuses me on why they chose to use swapdepth to set a depth