After reading some posts about this, I learned a lot, and now I want to share it with you all.
Flash is now just a display function. During the process, I read some other people's stuff and felt that paging seems to have a very simple way to implement it.
Basically it is transmitted using xml.
Both list components and datagrid can be used for display. I use dynamic text here because I think it is too troublesome to use components.
So I used a stupid method, there was no other way, I couldn’t find a better one~~~
The list[..] in the code below is the name of the dynamic text, and 15 items are displayed at a time.
//The display program is as follows:
//Frame name "list"
stop();
var logList = new XML();
var logroot;
var page:Number; //Current page
var Tpage:Number; //Save the total page
var Tnum:Number; //Total number of logs
var logname:String; //Log category name
vartemp;
var i:Number;
//Here I use an array to store the corresponding ID number. If you use components, you don’t have to be so troublesome.
var ids = new Array(15);
//Two buttons for turning pages
bn_u.enabled = false;
bn_d.enabled = false;
if (page == null or page<1) {
page = 1;
}
//-----------------------------
//Clear 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 function
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 to read nodes
while (temp.nextSibling != null) {
temp = temp.nextSibling;
i++;
//If it is displayed in another way, just change it.
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 logs"+Tnum+"Total articles"+Tpage+"The current page is "+page+"page"+"15/page";
bn_u.enabled = true;
bn_d.enabled = true;
} else {
pageInfo.text = "There are currently no logs.";
list.ltitle1.text = "Error reading data, please contact the administrator!";
}
}
//A custom format title function, fearing that 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, 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);
There is only one word for "cycle":
gotoAndPlay("list");
//Form a simple loop
Tree_list.asp:
//log is my log table, log_cat is the asp below the classification table. It 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
callTree_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 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
//Close rs
callTree_rsclose
callTree_conclose
response.write("</Tree>")
%>
The code seems to be very messy. I hope it can be helpful to friends who are doing this. If there are any bugs in the above, please tell me
. Source: www.flashbank.cn