flash和asp分页的一点心得与flash脚本

  看了这个的一些帖子,学到了很多东西,现在和大家一起分享

  flash现在只是一个显示的功能,过程中看了一些别人的东西,觉得分页似乎有很简单的实现方式.基本上都是用xml传送的.显示用 list 组件和 datagrid 都可以,这里我用的是动态文本,因为觉得组件用的太麻烦了.所以用了蠢办法,没办法,找不到更好的~~~下面代码中的 list[..]就是动态文本的名趁,一次显示15条

  //显示程序如下:

  //桢名称 "list"

  stop();

  var logList = new XML();

  var logroot;

  var page:Number; //当前页

  var Tpage:Number; //保存总页

  var Tnum:Number; //总日志数

  var logname:String; //日志分类名称

  var temp;

  var i:Number;

  //这里我用一个数组储存了对应的id号,如果用组件就不用这么麻烦了

  var ids = new Array(15);

  //两个按钮,用来翻页

  bn_u.enabled = false;

  bn_d.enabled = false;

  if (page == null or page<1) {

  page = 1;

  }

  //------------------------------

  //清除函数;

  function myclear() {

  for (i=1; i<16; i++) {

  ids[i-1] = 0;

  list["lbn"+i]._visible = false;

  list["ltitle"+i].text = "";

  list["lauthor"+i] = "";

  list["ltime"+i] = "";

  }

  }

  //--------------------------------------

  //--------------------------------------

  myclear();

  pageInfo.text = "正在读取数据...";

  logList.ignoreWhite = true;

  logList.load("Tree_list.asp?log_cat="+cat_id+"&page="+page);

  //------------------------------------------------

  //get数据函数

  function logFunc(e) {

  if (e) {

  logroot = logList.firstChild;

  logname = logroot.attributes.logname;

  Tpage = logroot.attributes.Tpage;

  Tnum = logroot.attributes.Tnum;

  temp = logroot.firstChild;

  list.ltitle1.text = Ftitle(temp.firstChild.nodeValue, 22);

  list.lauthor1 = temp.attributes.author;

  list.ltime1 = temp.attributes.Addtime;

  ids[0] = temp.attributes.id;

  i = 1;

  list.lbn1._visible = true;

  //循环读取节点

  while (temp.nextSibling != null) {

  temp = temp.nextSibling;

  i++;

  //如果是用别的方式显示,只需要改一下就可以了

  ids[i-1] = temp.attributes.id;

  list["lbn"+i]._visible = true;

  list["ltitle"+i].text = Ftitle(temp.firstChild.nodeValue, 22);

  list["lauthor"+i] = temp.attributes.author;

  list["ltime"+i] = temp.attributes.Addtime;

  }

  pageInfo.text = logname+"共有日志"+Tnum+"篇 共"+Tpage+"页 当前是第"+page+"页 "+"15/页";

  bn_u.enabled = true;

  bn_d.enabled = true;

  } else {

  pageInfo.text = "当前没有日志。";

  list.ltitle1.text = "读取数据出错,请联系管理员!";

  }

  }

  //一个自定义的格式标题的函数,怕标题太长

  function Ftitle(s, n) {

  if (length(s)>n) {

  s = s.substring(0, n-1)+"...";

  }

  return s;

  }

  logList.onLoad = logFunc;

  //-------------------------------------

  //按钮动作

  Bn_up = new Object();

  //按钮事件,判断页面大小是否超过值

  Bn_up.click = function(evt) {

  if (page>1) {

  _root.page--;

  gotoAndPlay("cycle");

  } else {

  stop();

  }

  };

  Bn_d = new Object();

  Bn_d.click = function(evt) {

  if (page<Tpage) {

  _root.page++;

  gotoAndPlay("cycle");

  } else {

  stop();

  }

  };

  bn_u.addEventListener("click", Bn_up);

  bn_d.addEventListener("click", Bn_d);

  桢"cycle"只有一个话:

  gotoAndPlay("list");

  //形成一个简单的循环

  Tree_list.asp:

  //log 是我的日志表 ,log_cat是分类表

  下面的asp很清楚了

  <?xml version="1.0" encoding="gb2312"?>

  <%

  Response.ContentType = "text/xml"

  Response.CacheControl = "no-cache"

  Response.AddHeader "Pragma", "no-cache"

  Response.Expires = 0

  dim log_cat,page,pageSize,Tnum,Tpage,log_name

  page=TreeRequest("page",1)

  log_cat=TreeRequest("log_cat",1)

  pageSize=15

  call Tree_rs

  if log_cat=0 or log_cat="" then

  sql="select * from log order by written_time DESC,log_ID DESC"

  else

  sql="select * from log,log_cat where log.cat_id=log_cat.ID and cat_id="&log_cat&" order by written_time DESC,log_ID DESC"

  End if

  rs.open sql,conn,1,1

  rs.PageSize=pageSize

  Tnum=rs.RecordCount

  Tpage=Int(Tnum/pageSize*-1)*-1

  if page="" then page=1

  if Tnum<>0 then rs.AbsolutePage=page

  if log_cat=0 or log_cat="" then

  log_name="[全部分类]"

  else

  log_name="["&rs("cat_name")&"]"

  End if

  '以下输出xml

  '------------------------------------------------

  response.write("<Tree logname='"&log_name&"' Tnum='"&Tnum&"' Tpage='"&Tpage&"'>")

  if rs.eof then

  rs.close

  else

  do while not rs.eof and pageSize>0

  response.write("<Trees author='"&rs("log_author")&"' Addtime='"&rs("written_time")&"' id='"&rs("log_ID")&"'>")

  response.write("<![CDATA["&rs("log_tittle")&"]]></Trees>")

  pageSize=pageSize-1

  rs.movenext

  loop

  rs.close

  End if

  //关闭rs

  call Tree_rsclose

  call Tree_conclose

  response.write("</Tree>")

  %>