Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

detect load completion from an array of images

Contributor ,
Jul 20, 2013 Jul 20, 2013

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?

TOPICS
ActionScript
946
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 20, 2013 Jul 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();

}

}

Translate
Community Expert ,
Jul 20, 2013 Jul 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();

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 21, 2013 Jul 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)}

          }

 

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2013 Jul 21, 2013

assign your banner's depth to be napolpics.length

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 21, 2013 Jul 21, 2013
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines