AS2 MovieClipLoader - 来自 XML 的图像。如果图像不存在,如何跳过加载?

发布于 2024-12-08 20:18:17 字数 1968 浏览 0 评论 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() )无法运行。

有人知道如何跳过丢失的缩略图吗?

感谢您的帮助, 阿图尔.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几味少女 2024-12-15 20:18:17

你应该添加:

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

我认为你应该测试:

if (loaded_counter >= total_thumbs)

你永远不知道......

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文