2011-10-08 22 views
0

我想基于XML制作缩略图网格。到目前为止,我已经完成了在舞台上加载和定位缩略图的代码。该代码使用:AS2 MovieClipLoader - 来自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())可以”运行。

任何人都有一个想法如何跳过丢失的缩略图?

感谢您的帮助, Artur。

+0

这是疯了...我不明白怎么人们使用movieClipLoader在网格中进行平滑的图像定位。当我试图定位图像而不等待所有缩略图完全加载时,然后在鼠标处于onRollOver(rollOver将我的拇指缩放至120%)时定位进度,我的拇指图像转到其他位置,而不是它们应该是:(:(。如何在定位过程中关闭鼠标事件,并在定位东西完成时打开? –

回答

0

您应该添加:

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

我想你应该测试:

if (loaded_counter >= total_thumbs) 

你永远不知道...

相关问题