AS2 MovieClipLoader - 来自 XML 的图像。如果图像不存在,如何跳过加载?
我正在尝试制作基于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该添加:
我认为你应该测试:
你永远不知道......
You should add :
And I think you should test :
You never know...