Pagination | Experience
Read this some of the posts, learned a lot of things, and now share with you
Flash is now just a display function, the process of seeing some other people's things, feel that pagination seems to have a very simple way of implementation. Basically, it's all in XML. Display with the list component and the DataGrid, and here I use dynamic text, Because I think the components used too much trouble. So with a stupid way, no way, can not find a better ~ ~ ~ ~ ~ The following code in the list[...] is the name of the dynamic text, which displays 15 at a time.
The display program is as follows:
Hardwood name "List"
Stop ();
var loglist = new XML ();
var logroot;
var Page:number; Current page
var Tpage:number; Save Total Page
var Tnum:number; Total log Count
var logname:string; Journal category name
var temp;
var I:number;
Here I use an array to store the corresponding ID number, if the component is not so cumbersome
var ids = new Array (15);
//two buttons for paging
bn_u.enabled = false;
bn_d.enabled = false;
if (page = = NULL or page<1) {
page = 1;
}
//------------------------------
//purge function;
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 = "reading data ...";
Loglist.ignorewhite = true;
Loglist.load ("tree_list.asp?log_cat=" +cat_id+ "&page=" +page);
//------------------------------------------------
//get data functions
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;
//Loop read node
while (temp.nextsibling!= null) {
temp = temp.nextsibling;
i++;
//If it is displayed in a different way, just change it to the
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+ "Total log" +tnum+ "+tpage+" page is currently the first "+page+" page "+ 15/page";
Bn_u.enabled = true;
Bn_d.enabled = true;
} else {
Pageinfo.text = "There is currently no log. ";
List.ltitle1.text = "Error reading data, please contact admin!" ";
}
}
A custom format title function that's afraid the title is too long
function Ftitle (s, N) {
if (length (s) >n) {
s = s.substring (0, n-1) + "...";
}
return s;
}
Loglist.onload = Logfunc;
//-------------------------------------
Button action
bn_up = new Object ();
Button event to determine whether the page size exceeds the value
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);
Frame "cycle" only one word:
gotoAndPlay ("list");
To form a simple loop
Tree_list.asp:
Log is my logging table, Log_cat is the category table
The following ASP is very clear
<?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=" [All Categories]
Else
log_name= "[" &rs ("Cat_name ") &"] "
End If
' the following output XML
'------------------------------------------------
RESPONSE.WRIte ("<tree logname= '" &log_name& "' tnum= '" &Tnum& "' tpage= '" &Tpage& "' > ')
if rs.eof Then
Rs.close
Else
do, 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
//Turn off RS
Call Tree_rsclose
Call Tree_conclose
Response.Write ("</Tree>")
% "
The code seems very messy, hope to be doing this friend a little help, if there is a bug, please advise