6、以上工作全部做好后,接下来就是添加代码了,当然如果你觉得界面还是不够漂亮,你可再调整调整,最后在主场景的第一帧添加如下代码:
System.useCodepage = true; //使用操作系统的传统代码页来解释外部文本文件
var xml = new XML(); //创建XML类
xml.load("pl_list.asp"); //加载外部文件
msg = "正在加载评论……";
xml.onLoad = function(ok) {
if (ok) {
init(); //加载成功后调用init函数
}
};
//解析外部文件
function init() {
_root.attachMovie("pllist", "pllist", 1); //为主场景添加一个pllist影片剪辑
_root.pllist.tot = "共"+xml.firstChild.attributes.tot+"条"+" 当前第"+xml.firstChild.attributes.curpage+"页";//获得所有评论数与当前页码
for (i=0; i drawPllist(i);//绘制评论列表 } _root.pagecount(xml.firstChild.attributes.tot); msg = "加载成功"; } //评论列表绘制函数 function drawPllist(c) { _root.pllist.attachMovie("pl", "pl"+c, c);//将库中影片剪辑附加到pllist影片剪辑中 with (_root.pllist["pl"+c]) {//这句可以用with(eval("_root.pllist.pl"+c)){替换 _x = 20; //设置厅距离 _y = 20+c*100;//设置上距离 user = xml.firstChild.childNodes[c].childNodes[0];//获得呢称 dateandtime = xml.firstChild.childNodes[c].childNodes[1].toString();//获得评论时间 contents = xml.firstChild.childNodes[c].childNodes[2].toString();//获得评论内容 } var xid = xml.firstChild.childNodes[c].childNodes[3].toString();//获得评论id,用于删除操作 _root.pllist["pl"+c].del.onRelease = function() { xml.load("pl_del.asp?id="+substring(xid, 5, length(xid)-9)); xml.onLoad = function(ok) { if (ok) { msg = "删除成功!"; } xml.load("pl_list.asp");//删除后再次加载 xml.onLoad = function(ok) { if (ok) { init(); } }; }; }; } //翻页处理 function pagecount(tot) { if (tot%5 == 0) { //计算页数 pages = int(tot/5); } else { pages = int(tot/5)+1; } for (var j = 1; j<=pages; j++) { drawpage(j); } } //绘制翻页按钮 function drawpage(j) { _root.pllist.attachMovie("gopage", "gopage"+j, j+10); with (_root.pllist["gopage"+j]) { _x = 100+j*30; _y = 520; curpage = j; } _root.pllist["gopage"+j].onRelease = function() { xml.load("pl_list.asp?page="+j); msg = "正在加载评论……"; xml.onLoad = function(ok) { if (ok) { init(); } }; }; _root.pllist["gopage"+j].onRollOver = function() { this.gotoAndStop(2); }; _root.pllist["gopage"+j].onRollOut = function() { this.gotoAndStop(1); }; } //tjpl按钮事件,用于添加评论 _root.tjpl.onRelease = function() { if (_root.u.text != "" and _root.c.text != "") { _root.msg = "正在添加!"; xml.load("pl_fb.asp?newsid=1&user="+_root.u.text+"&content="+_root.c.text); xml.onLoad = function(ok) { if (ok) { msg = "添加成功!"; } xml.load("pl_list.asp"); xml.onLoad = function(ok) { if (ok) { init(); } }; }; } else { msg = "呢称或内容为空,添加失败!"; } }; //tjno按钮事件,用于清空呢称与内容,以便重新填写 _root.tjno.onRelease = function() { _root.c.text = ""; _root.u.text = ""; }; 我希望大家在阅读本篇文章时能够与前一篇文章对比起来阅读,由于本文为了和上一篇文章对照,而且采用了与上一篇同样的服务器端代码,因此有些地方在程序开发时就显得不尽人意。例如在FLASH调用xml时,习惯用attributes这个对象去获得属性值,而本篇却全部采用了元素节点,害得文中在取删除id就只好通过字符串函数截取,希望大家在开发应用系统时注意。![]()
