flash和asp分頁的一點心得與flash指令碼

來源:互聯網
上載者:User

看了這個的一些文章,學到了很多東西,現在和大家一起分享
  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>")
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.