XML图片加载示例,带分页效果:
//=========初始化==========
//页数,默认0表示第一页
var curPage_num:Number = 0;
//每页容量
var sizPage_num:Number = 15;
//每排张数
var pai_num:Number = 5;
//图片宽度、高度
var width_num:Number = 80;
var height_num:Number = 80;
//图片与图片之间的间隔
var jia_num:Number = 20;
//=============================
var url_array:Array = new Array();
this.pagedown_btn._visible = false;
this.pageup_btn._visible = false;
//=========透明函数========
function alpha_func(_mc:MovieClip) {
_mc._alpha = 5;
_mc.onEnterFrame = function() {
this._alpha += 5;
this._alpha>=95 ? delete this.onEnterFrame : 闪吧;
};
}
//============MCL类===========
var _mcl:MovieClipLoader = new MovieClipLoader();
this.onLoadInit = function(_mc:MovieClip) {
_mc._txt.removeTextField();
_mc._width = 80;
_mc._height = 80;
alpha_func(_mc);
};
//=========加载进度显示==============
this.onLoadProgress = function(_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
_mc.createTextField("_txt", 200, 20, 10, 60, 30);
_mc._txt.textColor = 0xff0000;
_mc._txt.text = Math.floor((bytesLoaded/bytesTotal*10000)/100)+"%";
};
//=========加载错误提示==============
this.onLoadError = function(_mc:MovieClip) {
_mc.createTextField("_txt", 200, 20, 10, 60, 30);
_mc._txt.textColor = 0xff0000;
_mc._txt.text = "加载失败!";
};
_mcl.addListener(this);
//===========XML加载============
var url_xml:XML = new XML();
url_xml.ignoreWhite = true;
url_xml.onLoad = function(success) {
if (success) {
for (var d:Number = 0; d<this.firstChild.childNodes.length; d++) {
url_array.push(this.firstChild.childNodes[d].attributes.name);
}
enabled_func();
} else {
trace("xml文档加载失败!");
}
};
url_xml.load("xml/img.xml");
var show_func:Function = function (_page:Number) {
for (var d:Number = 0; d<sizPage_num; d++) {
//attachMovie("pic_mc", "pic_mc"+d, d+1000, {_x:20+Math.floor(d/Math.floor(Math.sqrt(sizPage_num)))*100, _y:20+d%Math.floor(Math.sqrt(sizPage_num))*100});
attachMovie("pic_mc", "pic_mc"+d, d+1000, {_x:20+d%pai_num*(height_num+jia_num), _y:20+Math.floor(d/pai_num)*(width_num+jia_num)});
}
for (var d:Number = 0; d<sizPage_num; d++) {
if (_page*sizPage_num+d<=sizPage_num) {
this.pageup_btn.enabled = false;
} else if (_page*sizPage_num+d == url_array.length-1) {
this.pagedown_btn.enabled = false;
} else if (_page*sizPage_num+d>=url_array.length) {
break;
} else {
this.pageup_btn.enabled = true;
this.pagedown_btn.enabled = true;
}
_mcl.loadClip(url_array[_page*sizPage_num+d], this["pic_mc"+d]);
}
};
function enabled_func() {
this.pagedown_btn._visible = true;
this.pageup_btn._visible = true;
show_func(curPage_num);
this.pagedown_btn.onRelease = function() {
if (curPage_num<Math.floor(url_array.length/sizPage_num)) {
curPage_num++;
show_func(curPage_num);
}
};
this.pageup_btn.onRelease = function() {
if (curPage_num>0) {
curPage_num--;
show_func(curPage_num);
}
};
}
同时附带另一个源文件,图片依次加载效果(也就是加载完一个接着加载下一个)。以上两个实例都是在经典论坛回贴时做的,用了人家现成的图片,虽不算什么特别的东东,但AS是我原创。
附件:
XML加载图片分页.rar
图片依次加载.rar