0

I'm trying to make thumbnails-grid based on XML. So far I have done code for loading and positioning thumbnails on stage. The code I use:

function loadXML(loaded) {
  if (loaded) {
    xmlNode = this.firstChild;
    imgName = [];
    image = [];
    description = [];
    thumbnails = [];
    url = [];
    _global.total = xmlNode.childNodes.length;
    for (i=0; i<_global.total; i++) {
       imgName[i] = xmlNode.childNodes[i].attributes.image_name;
       image[i] = xmlNode.childNodes[i].attributes.path;
       description[i] = xmlNode.childNodes[i].attributes.details;
       thumbnails[i] = xmlNode.childNodes[i].attributes.path + "tn_" + xmlNode.childNodes[i].attributes.image_name;
       url[i] ="#"+ xmlNode.childNodes[i].attributes.path + xmlNode.childNodes[i].attributes.image_name;
       thumbnailer(i);
     }
   } else {
     trace("file not loaded!");
   }
}

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad =loadXML;
xmlData.load("myImages.xml");

function thumbnailer(k){
   loaded_counter=0;
   total_thumbs = _global.total;
   var container = thumbnail_mc.createEmptyMovieClip("th"+k,thumbnail_mc.getNextHighestDepth());
   var image = container.createEmptyMovieClip("img", container.getNextHighestDepth());

   tlistener = new Object();
   tlistener.onLoadInit = function(target_mc) { 
      target_mc.onRelease = function() {
          getURL (url[k], "_self");
      };
      target_mc.onRollOver = function() {
          target_mc._alpha=50;
      };
      target_mc.onRollOut = target_mc.onDragOut = function(){
          target_mc._alpha=100;
      };
      loaded_counter++;
      if(loaded_counter==total_thumbs){
          build_grid();
      }  
   };
   image_mcl = new MovieClipLoader();
   image_mcl.addListener(tlistener);
   image_mcl.loadClip(thumbnails[k], "thumbnail_mc.th"+k+".img");
}

Now, when some of the thumbnails are missing in folder, the code is stuck on line: loaded_counter==total_thumbs , and positioning stuff ( build_grid() ) can't run.

Anyone have an idea how to skip missing thumbnails?

Thanks for any help, Artur.

Artur Filipiak
  • 9,027
  • 4
  • 30
  • 56
  • This is crazy... I don't understand how people make smooth image positioning in grid with movieClipLoader. When I'm trying positioning images without waiting when all of the thumbnails are fully loaded, then on positioning progress when mouse is onRollOver (rollOver scale my thumbs to 120%) my thumb images goes to other position than they should be :( :( . How to turn off mouse events on positioning progress, and turn-on when positioning stuff is complete?? – Artur Filipiak Oct 09 '11 at 14:25

1 Answers1

0

You should add :

tlistener.onLoadError = function() {
  loaded_counter++;
  if(loaded_counter==total_thumbs){
      build_grid();
  }  
}

And I think you should test :

if (loaded_counter >= total_thumbs)

You never know...