昨天给一个朋友做课件,用到了XML写路径加载图片,我觉得对部分朋友可能有借鉴的价值,所以发上来。由于图片太多,所以包中没有图片,但大家可以从XML中看到图片的路径和名称该怎样写。
FLASH:
#include "tween_as.as"
///////
System.useCodepage = true;
var pic_xml:XML = new XML();
var url_array:Array = new Array();
pic_xml.ignoreWhite = true;
pic_xml.onLoad = function() {
for (var d:Number = 0; d<this.firstChild.childNodes.length; d++) {
var path_array:Array = new Array();
for (var c:Number = 0; c<this.firstChild.childNodes[d].childNodes.length; c++) {
path_array.push(this.firstChild.childNodes[d].childNodes[c].firstChild.nodeValue);
}
url_array.push(path_array);
}
//trace(url_array);
};
pic_xml.load("path.xml");
///////////
var tween_array:Array = [myBlind, myFade, myFly, myPhoto, myPixelDissolove, myZoom, mySqueeze, myWipe];
this.createEmptyMovieClip("load_mc", this.getNextHighestDepth());
this.load_mc.createEmptyMovieClip("pic_mc", this.getNextHighestDepth());
var mcload:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target:MovieClip) {
target._width = Stage.width;
target._height = Stage.height;
target._x = -550/2;
target._y = -400/2;
target._parent._x = 550/2;
target._parent._y = 400/2;
target.onRelease = function() {
xiabiao_num++;
xiabiao_num %= url_array[zhu_num].length;
mcload.loadClip(url_array[zhu_num][xiabiao_num], load_mc.pic_mc);
};
tween_array[Math.floor(Math.random()*tween_array.length)](target._parent);
};
mcload.addListener(mclListener);
////////////////////
btn_mc.swapDepths(this.getNextHighestDepth());
var xiabiao_num:Number = 0;
var zhu_num:Number = 0;
for (var d:Number = 4; d>=0; d--) {
this.btn_mc["btn"+d].id = d;
this.btn_mc["btn"+d].onRelease = function() {
xiabiao_num = 0;
zhu_num = this.id;
mcload.loadClip(url_array[zhu_num][xiabiao_num], load_mc.pic_mc);
};
}
/////////
this.btn_mc.fanhui_btn.onRelease = function() {
_root.gotoAndStop(1);
};
function auto_func() {
xiabiao_num++;
xiabiao_num %= url_array[zhu_num].length;
trace(url_array[zhu_num][xiabiao_num]);
mcload.loadClip(url_array[zhu_num][xiabiao_num], load_mc.pic_mc);
}
this.btn_mc.auto_btn.onRelease = function() {
auto_func();
clearInterval(id);
id = setInterval(auto_func, 12000);
};
this.btn_mc.hand_btn.onRelease = function() {
auto_func();
clearInterval(id);
};
this.btn_mc.one_btn.onRelease = function() {
xiabiao_num = 0;
mcload.loadClip(url_array[zhu_num][xiabiao_num], load_mc.pic_mc);
};
this.btn_mc.over_btn.onRelease = function() {
xiabiao_num = url_array[zhu_num].length-1;
mcload.loadClip(url_array[zhu_num][xiabiao_num], load_mc.pic_mc);
};
this.btn_mc.next_btn.onRelease = auto_func;
this.btn_mc.prev_btn.onRelease = function() {
xiabiao_num--;
if (xiabiao_num<0) {
xiabiao_num = url_array[zhu_num].length-1;
}
mcload.loadClip(url_array[zhu_num][xiabiao_num], load_mc.pic_mc);
};
//////////////
this.miyu_txt.removeTextField();
XML:
<?xml version="1.0" encoding="gb2312"?>
<part>
<path>
<url>\images\1娃娃鱼\娃娃鱼01.jpg</url>
<url>\images\1娃娃鱼\娃娃鱼02.jpg</url>
<url>\images\1娃娃鱼\娃娃鱼03.jpg</url>
<url>\images\1娃娃鱼\娃娃鱼04.jpg</url>
<url>\images\1娃娃鱼\娃娃鱼05.jpg</url>
<url>\images\1娃娃鱼\娃娃鱼06.jpg</url>
<url>\images\1娃娃鱼\娃娃鱼07.jpg</url>
<url>\images\1娃娃鱼\娃娃鱼08.jpg</url>
<url>\images\1娃娃鱼\娃娃鱼09.jpg</url>
</path>
<path>
<url>\images\2中华鲟\中华鲟01.jpg</url>
<url>\images\2中华鲟\中华鲟02.jpg</url>
<url>\images\2中华鲟\中华鲟03.jpg</url>
<url>\images\2中华鲟\中华鲟04.jpg</url>
<url>\images\2中华鲟\中华鲟05.jpg</url>
</path>
<path>
<url>\images\4.1老虎\老虎1.jpg</url>
<url>\images\4.1老虎\老虎2.jpg</url>
<url>\images\4.1老虎\老虎4.jpg</url>
<url>\images\4.1老虎\老虎4.jpg</url>
<url>\images\4.1老虎\老虎5.jpg</url>
<url>\images\4.1老虎\老虎6.jpg</url>
<url>\images\4.1老虎\老虎7.jpg</url>
<url>\images\4.2大象\大象1.jpg</url>
<url>\images\4.2大象\大象2.jpg</url>
<url>\images\4.2大象\大象3.jpg</url>
<url>\images\4.2大象\大象4.jpg</url>
<url>\images\4.2大象\大象5.jpg</url>
<url>\images\4.2大象\大象6.jpg</url>
<url>\images\4.2大象\大象7.jpg</url>
<url>\images\4.2大象\大象8.jpg</url>
<url>\images\4.2大象\大象9.jpg</url>
<url>\images\4.3狗熊\狗熊1.jpg</url>
<url>\images\4.3狗熊\狗熊2.jpg</url>
<url>\images\4.3狗熊\狗熊3.jpg</url>
<url>\images\4.3狗熊\狗熊4.jpg</url>
<url>\images\4.4孔雀\孔雀1.jpg</url>
<url>\images\4.4孔雀\孔雀2.jpg</url>
<url>\images\4.4孔雀\孔雀3.jpg</url>
<url>\images\4.4孔雀\孔雀4.jpg</url>
<url>\images\4.4孔雀\孔雀5.jpg</url>
<url>\images\4.4孔雀\孔雀6.jpg</url>
<url>\images\4.4孔雀\孔雀7.jpg</url>
<url>\images\4.4孔雀\孔雀8.jpg</url>
<url>\images\4.5其他\其他动物1.jpg</url>
<url>\images\4.5其他\其他动物2.jpg</url>
<url>\images\4.5其他\其他动物3.jpg</url>
<url>\images\4.5其他\其他动物4.jpg</url>
<url>\images\4.5其他\其他动物5.jpg</url>
<url>\images\4.5其他\其他动物6.jpg</url>
<url>\images\4.5其他\其他动物7.jpg</url>
<url>\images\4.5其他\其他动物8.jpg</url>
<url>\images\4.5其他\其他动物9.jpg</url>
<url>\images\4.5其他\其他动物10.jpg</url>
<url>\images\4.5其他\其他动物11.jpg</url>
<url>\images\4.5其他\其他动物12.jpg</url>
<url>\images\4.5其他\其他动物13.jpg</url>
<url>\images\4.5其他\其他动物14.jpg</url>
</path>
<path>
<url>\images\5青蛙\青蛙8.jpg</url>
<url>\images\5青蛙\青蛙1.jpg</url>
<url>\images\5青蛙\青蛙3.jpg</url>
<url>\images\5青蛙\青蛙4.jpg</url>
<url>\images\5青蛙\青蛙5.jpg</url>
<url>\images\5青蛙\青蛙6.jpg</url>
<url>\images\5青蛙\青蛙7.jpg</url>
<url>\images\5青蛙\青蛙0.jpg</url>
</path>
<path>
<url>\images\6.1狗\狗1.jpg</url>
<url>\images\6.1狗\狗2.jpg</url>
<url>\images\6.1狗\狗3.jpg</url>
<url>\images\6.1狗\狗4.jpg</url>
</path>
</part>
附件:
XML路径加载.rar