//XML文件部分代码(imgList.xml)
//----------------------------------------------------------------------------------
http://www.ebidea.com<;/list>
http://www.ebidea.com<;/list>
http://www.ebidea.com<;/list>
http://www.ebidea.com<;/list>
http://www.ebidea.com<;/list>
http://www.ebidea.com<;/list>
http://www.ebidea.com<;/list>
http://www.ebidea.com<;/list>
http://www.ebidea.com<;/list>
http://www.ebidea.com<;/list>
http://www.ebidea.com<;/list>
//flash AS代码:
//----------------------------------------------------------------------------------
Stage.showMenu = false;
Stage.scaleMode = "noScale";
fscommand(allowscale, true);
//初始化屏幕大小
System.useCodepage = true;
//中文支持
imgW = 580;
imgH = 386;
//初始化场景宽度和高度
jTime = 1500;//初始化滚动间隔时间,默认1.5秒
var myLoad = new XML();
myLoad.ignoreWhite = true;
myLoad.load("imgList.xml");
myLoad.onLoad = function(success) {//装载xml文件
if (success) {
createEmptyMovieClip("img_mc", -16383);//装载成功,初始化滚动mc元件
img_mc.createEmptyMovieClip("loadImg0", 1);//创建loading图片的子元件
img_mc._x = -imgW;//初始化坐标位置
x = 0;//初始化显示图片的指针
imgList();//执行函数imgList();
makeBtn();//创建控制按钮
} else {
trace("错误!装载xml文件不成功!");//返回错误信息
}
};
function makeBtn() {//本函数初始化控制按钮元件
_root.attachMovie("next_btn", "n_btn", 50);//连接向后的按钮
_root.attachMovie("next_btn", "u_btn", 51);//连接向前的按钮
u_btn._rotation = 180;//控制向前的按钮翻转角度
u_btn._x = imgW-50;//
u_btn._y = imgH-30;//
n_btn._x = imgW-25;//
n_btn._y = imgH-30;//初始化两个按钮的位置
u_btn.onRelease = MoveLeft;//当点此按钮的时候执行向左滚动的函数
n_btn.onRelease = MoveRight;//‘’‘’‘’‘’‘’‘右滚动的函数
u_btn.onRollOver = function() {//当鼠标在本按钮上的时候清除自动滚动选项
clearInterval(MA);
};
u_btn.onRollOut = function() {//当鼠标离开后继续自动滚动
MA = setInterval(MoveLeft, jTime);
};
n_btn.onRollOver = function() {//
clearInterval(MA);
};
n_btn.onRollOut = function() {//
MA = setInterval(MoveLeft, jTime);
};
}
function imgList() {//xml分析函数,并构造滚动元件
myList = myLoad.firstChild.childNodes;
myListLen = myList.length;
for (i=1; i
img_mc.loadImg0.duplicateMovieClip("loadImg"+i, i+1);
}
for (i=0; i
loadImgs = eval(img_mc["loadImg"+i]);
mcbtns = img_mc.attachMovie("btn_mc", "btn"+i, i+myListLen+4);//连接图片按钮
loadImgs.btn = mcbtns;//初始化各图片对应的按钮
loadImgs.i = i;//初始化当前图片的指针
loadImgs.loadImg();//执行图片装载函数
}
}
function moveImg() {//图片滚动函数
if (x>myListLen) {//控制向左的循环
x = 1;
img_mc._x = 0;
}
if (x<1) {//控制向右循环
x = myListLen;
img_mc._x = -img_mc._width+imgW;
}
textValue(myList[x-1].attributes.info);//执行文本显示函数
onEnterFrame = function () {//循环检测滚动
targetx = -x*imgW;
img_mc._x += (targetx-img_mc._x)*0.2;
if (Math.abs(targetx-img_mc._x)<=0.2) {//位置符合后停止循环
img_mc._x = targetx;
delete onEnterFrame;
}
};
}
function MoveLeft() {//向左滚动
x++;
moveImg();
}
function MoveRight() {//向右滚动
x--;
moveImg();
}
MA = setInterval(MoveLeft, jTime);//自动滚动
MovieClip.prototype.loadImg = function() {//mc装载图片函数
if (this.i == 0) {//在最前增加张最后的图片,方便向左循环。
this.loadMovie(myList[myListLen-1].attributes.path);
} else if (this.i == myListLen+1) {//在最后帧位置怎加第一张图片,方便向右循环
this.loadMovie(myList[0].attributes.path);
} else {
this.loadMovie(myList[this.i-1].attributes.path);
}
this._x = this.i*imgW;//初始化位置,逐个相连接
this.btn._x = this._x;//控制图片上方的透明按钮对应位置
this.btn._width = imgW;//
this.btn._height = imgH;//控制’‘’‘’‘’‘对应尺寸
this.btn.onRelease = function() {//点击图片按钮连接网址
getURL(myList[this.i-1].childNodes);
};
this.btn.onRollOver = function() {//当鼠标在图片上停止自动滚动
clearInterval(MA);
};
this.btn.onRollOut = function() {//当鼠标离开图片,继续自动滚动
MA = setInterval(MoveLeft, jTime);
};
};
textFiled();
function textValue(myValue) {//为文本框显示图片对应的说明;
myformat = new TextFormat();
myformat.align = "right";
myformat.color = 0xffffff;
myformat.font = "宋体";
myformat.size = 12;
myformat.bullet = false;
myformat.underline = false;
_root.createTextField("mytext", 20, imgW-360, imgH-38, 300, 16);
mytext.selectable = false;
mytext.text = myValue;
mytext.setTextFormat(myformat);
}