0

我正在尝试基于 XML 制作缩略图网格。到目前为止,我已经完成了在舞台上加载和定位缩略图的代码。我使用的代码:

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");
}

现在,当文件夹中缺少一些缩略图时,代码卡在了线上:loaded_counter==total_thumbs,并且定位的东西(build_grid())无法运行。

任何人都知道如何跳过丢失的缩略图?

感谢您的帮助,阿图尔。

4

1 回答 1

0

您应该添加:

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

我认为你应该测试:

if (loaded_counter >= total_thumbs)

你永远不会知道...

于 2012-08-08T20:47:55.520 回答