Skip to main content
Inspiring
July 20, 2013
Answered

detect load completion from an array of images

  • July 20, 2013
  • 1 reply
  • 1006 views

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?

This topic has been closed for replies.
Correct answer kglad

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();

}

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
July 20, 2013

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();

}

}

JonnyDLAuthor
Inspiring
July 21, 2013

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, 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)}

          }

 

};

kglad
Community Expert
Community Expert
July 21, 2013

assign your banner's depth to be napolpics.length