开发者

AS2 MovieClipLoader - images from XML. How to skip image loading if not exist?

开发者 https://www.devze.com 2023-04-11 12:12 出处:网络
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:

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.


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号