用Flash和XML構建論壇執行個體(2)

來源:互聯網
上載者:User
三、查看本文

  查看本文,即是在伺服器端接收從Flash端發送過來的ID號,根據ID號去查詢資料庫,將查詢的結果用XML格式返回到Flash端。

  A、傳遞的XML

  1、請求報文

 <FILE ><ID>要查看的主題的ID號</ID></FILE >

  2、響應報文

 <FILE id="id號" title="主題" author="作者" content="內容" reply="回複的內容"></FILE>

  B、Flash端

  1、在第二幀的情境中建立十個按鈕,分別將執行個體命名為“filebtn1”、“filebtn2”、“filebtn3”、“filebtn4”、“filebtn5”、“filebtn6”、“filebtn7”、“filebtn8”、“filebtn9”、“filebtn10”。擺放位置及顯示內容2所示。

  2、在Button filebtn1的Action Script面板上增加如下的語句:

 on(release){
fileXml1 = new XML(); file://注釋1
fileElement1 = fileXml1.createElement("FILE"); file://注釋2
idElement1 = fileXml1.createElement("ID"); file://注釋3
idNode1 = fileXml1.createTextNode("id");
idNode1.nodeValue = _root.fileId1;
idElement1.appendChild(idNode1); file://注釋4
fileElement1.appendChild(idElement1);
fileXml1.appendChild(fileElement1);
_root.fileNowId = _root.fileId1; file://注釋5
fileRepley1 = new XML();
fileRepley1.onLoad = onFileReply1; file://注釋6
function onFileReply1 (filesuccess1) {
if (filesuccess1) {
_root.filetxt = fileRepley1.firstChild.attributes.title + fileRepley1.firstChild.attributes.author + fileRepley1.firstChild.attributes.content + fileRepley1.firstChild.attributes.reply; file://注釋7
_root.gotoAndPlay("content");
}
}
fileXml1.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley1); file://注釋8
}

注釋1:建立一個XML對象。
  注釋2:建立一個FILE結點對象。
  注釋3:建立一個ID結點對象。
  注釋4:分別將FILE結點對象和ID結點對象增加到XML對象中去。
  注釋5:儲存傳送的ID號到臨時變數。
  注釋6:設定onLoad響應函數。
  注釋7:將從伺服器返回的結果顯示出來。
  注釋8:利用sendAndLoad()函數,將Flash端的XML對象發送到伺服器端,並接收從伺服器端返回的XML對象。

  3、在Button filebtn2的Action Script面板上增加如下的語句:

 on(release){
fileXml2 = new XML();
fileElement2 = fileXml2.createElement("FILE");
idElement2 = fileXml2.createElement("ID");
idNode2 = fileXml2.createTextNode("id");
idNode2.nodeValue = _root.fileId2;
idElement2.appendChild(idNode2);
fileElement2.appendChild(idElement2);
fileXml2.appendChild(fileElement2);
_root.fileNowId = _root.fileId2;
fileRepley2 = new XML();
fileRepley2.onLoad = onFileReply2;
function onFileReply2 (filesuccess2) {
if (filesuccess2) {
_root.filetxt = fileRepley2.firstChild.attributes.title + fileRepley2.firstChild.attributes.author + fileRepley2.firstChild.attributes.content + fileRepley2.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml2.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley2);
}
 
  4、在Button filebtn3的Action Script面板上增加如下的語句:

 on(release){
fileXml3 = new XML();
fileElement3 = fileXml3.createElement("FILE");
idElement3 = fileXml3.createElement("ID");
idNode3 = fileXml3.createTextNode("id");
idNode3.nodeValue = _root.fileId3;
idElement3.appendChild(idNode3);
fileElement3.appendChild(idElement3);
fileXml3.appendChild(fileElement3);
_root.fileNowId = _root.fileId3;

fileRepley3 = new XML();
fileRepley3.onLoad = onFileReply3;
function onFileReply3 (filesuccess3) {
if (filesuccess3) {
_root.filetxt = fileRepley3.firstChild.attributes.title + fileRepley3.firstChild.attributes.author + fileRepley3.firstChild.attributes.content + fileRepley3.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml3.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley3);
}

  5、在Button filebtn4的Action Script面板上增加如下的語句:

 on(release){
fileXml4 = new XML();
fileElement4 = fileXml4.createElement("FILE");
idElement4 = fileXml4.createElement("ID");
idNode4 = fileXml4.createTextNode("id");
idNode4.nodeValue = _root.fileId4;
idElement4.appendChild(idNode4);
fileElement4.appendChild(idElement4);
fileXml4.appendChild(fileElement4);
_root.fileNowId = _root.fileId4;

fileRepley4 = new XML();
fileRepley4.onLoad = onFileReply4;
function onFileReply4 (filesuccess4) {
if (filesuccess4) {
_root.filetxt = fileRepley4.firstChild.attributes.title + fileRepley4.firstChild.attributes.author + fileRepley4.firstChild.attributes.content + fileRepley4.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml4.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley4);
}

  6、在Button filebtn5的Action Script面板上增加如下的語句:

 on(release){
fileXml5 = new XML();
fileElement5 = fileXml5.createElement("FILE");
idElement5 = fileXml5.createElement("ID");
idNode5 = fileXml5.createTextNode("id");
idNode5.nodeValue = _root.fileId5;
idElement5.appendChild(idNode5);
fileElement5.appendChild(idElement5);
fileXml5.appendChild(fileElement5);
_root.fileNowId = _root.fileId5;

fileRepley5 = new XML();
fileRepley5.onLoad = onFileReply5;
function onFileReply5 (filesuccess5) {
if (filesuccess5) {
_root.filetxt = fileRepley5.firstChild.attributes.title + fileRepley5.firstChild.attributes.author + fileRepley5.firstChild.attributes.content + fileRepley5.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml5.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley5);
}

  7、在Button filebtn6的Action Script面板上增加如下的語句:

 on(release){
fileXml6 = new XML();
fileElement6 = fileXml6.createElement("FILE");
idElement6 = fileXml6.createElement("ID");
idNode6 = fileXml6.createTextNode("id");
idNode6.nodeValue = _root.fileId6;
idElement6.appendChild(idNode6);
fileElement6.appendChild(idElement6);
fileXml6.appendChild(fileElement6);
_root.fileNowId = _root.fileId6;

fileRepley6 = new XML();
fileRepley6.onLoad = onFileReply6;
function onFileReply6 (filesuccess6) {
if (filesuccess6) {
_root.filetxt = fileRepley6.firstChild.attributes.title + fileRepley6.firstChild.attributes.author + fileRepley6.firstChild.attributes.content + fileRepley6.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml6.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley6);
}

  8、在Button filebtn7的Action Script面板上增加如下的語句:

 on(release){
fileXml7 = new XML();
fileElement7 = fileXml7.createElement("FILE");
idElement7 = fileXml7.createElement("ID");
idNode7 = fileXml7.createTextNode("id");
idNode7.nodeValue = _root.fileId7;
idElement7.appendChild(idNode7);
fileElement7.appendChild(idElement7);
fileXml7.appendChild(fileElement7);
_root.fileNowId = _root.fileId7;

fileRepley7 = new XML();
fileRepley7.onLoad = onFileReply7;
function onFileReply7 (filesuccess7) {
if (filesuccess7) {
_root.filetxt = fileRepley7.firstChild.attributes.title + fileRepley7.firstChild.attributes.author + fileRepley7.firstChild.attributes.content + fileRepley7.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml7.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley7);
}

  9、在Button filebtn8的Action Script面板上增加如下的語句:

 on(release){
fileXml8 = new XML();
fileElement8 = fileXml8.createElement("FILE");
idElement8 = fileXml8.createElement("ID");
idNode8 = fileXml8.createTextNode("id");
idNode8.nodeValue = _root.fileId8;
idElement8.appendChild(idNode8);
fileElement8.appendChild(idElement8);
fileXml8.appendChild(fileElement8);
_root.fileNowId = _root.fileId8;

fileRepley8 = new XML();
fileRepley8.onLoad = onFileReply8;
function onFileReply8 (filesuccess8) {
if (filesuccess8) {
_root.filetxt = fileRepley8.firstChild.attributes.title + fileRepley8.firstChild.attributes.author + fileRepley8.firstChild.attributes.content + fileRepley8.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml8.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley8);
}

  10、在Button filebtn9的Action Script面板上增加如下的語句:

 on(release){
fileXml9 = new XML();
fileElement9 = fileXml9.createElement("FILE");
idElement9 = fileXml9.createElement("ID");
idNode9 = fileXml9.createTextNode("id");
idNode9.nodeValue = _root.fileId9;
idElement9.appendChild(idNode9);
fileElement9.appendChild(idElement9);
fileXml9.appendChild(fileElement9);
_root.fileNowId = _root.fileId9;

fileRepley9 = new XML();
fileRepley9.onLoad = onFileReply9;
function onFileReply9 (filesuccess9) {
if (filesuccess9) {
_root.filetxt = fileRepley9.firstChild.attributes.title + fileRepley9.firstChild.attributes.author + fileRepley9.firstChild.attributes.content + fileRepley9.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml9.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley9);
}

  11、在Button filebtn10的Action Script面板上增加如下的語句:

 on(release){
fileXml10 = new XML();
fileElement10 = fileXml10.createElement("FILE");
idElement10 = fileXml10.createElement("ID");
idNode10 = fileXml10.createTextNode("id");
idNode10.nodeValue = _root.fileId10;
idElement10.appendChild(idNode10);
fileElement10.appendChild(idElement10);
fileXml10.appendChild(fileElement10);
_root.fileNowId = _root.fileId10;

fileRepley10 = new XML();
fileRepley10.onLoad = onFileReply10;
function onFileReply10 (filesuccess10) {
if (filesuccess10) {
_root.filetxt = fileRepley10.firstChild.attributes.title + fileRepley10.firstChild.attributes.author + fileRepley10.firstChild.attributes.content + fileRepley10.firstChild.attributes.reply;
_root.gotoAndPlay("content");
}
}
fileXml10.sendAndLoad("http://localhost/xmlbbs/file.asp", fileRepley10);
}
 
  12、在情境的第三幀上增加主要畫面格,並設定此幀的標籤為“content”,在此幀的Action Script面板上面增加如下語句:stop();

  利用文字框工具在此幀的情境中拉一個文字框用來顯示主題的本文,類型為Dynamic type,var變數設定為“filetxt”。

  C、Asp端

  建立一個Asp檔案,儲存為file.asp,增加如下的內容:

 <%
Set MyFileObject = Server.CreateObject("Scripting.FileSystemObject") ‘注釋1
Set MyTextFile = MyFileObject.CreateTextFile("G:\寫作\flashxmlbbs\login.xml", 8, TRUE)
MyTextFile.WriteLine(Request.Form) ‘注釋2

set objDom = server.CreateObject("microsoft.xmldom") ‘注釋3
objDom.loadxml(Request.Form) ‘注釋4
set objid = objdom.documentElement.SelectSingleNode("//FILE/ID") ‘注釋5
id = objid.text

'判斷
set conn=Server.CreateObject("ADODB.Connection") ‘注釋6
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/xmlbbs/xmlbbs.mdb")
set rs=Server.CreateObject("ADODB.Recordset")
strSql="select * from FileInfo where id = " & id ‘注釋7
rs.open strSql,conn, 1, 1
title = ""
author = ""
content = ""
if not(rs.bof and rs.eof) then ‘注釋8
id = rs("id")
title = rs("title")
author = rs("author")
content = rs("content")
end if

'要單獨處理回複
rs.close
reply = ""
strSql="select * from FileInfo where fid = " & id ‘注釋9
rs.open strSql,conn, 1, 1
do while not rs.eof
reply = reply & " " & rs("content") ‘注釋10
rs.moveNext ‘注釋11
loop
rs.close
conn.close
'返回
response.write("<FILE id=""" & id & """ title=""" & title & """ author=""" & author & """ content=""" & content & """ reply=""" & reply & """></FILE>") ‘注釋12
%>

  注釋1:建立一個臨時檔案對象。

  注釋2:將從Flash端傳來的XML字串寫到臨時檔案中。

  注釋3:建立一個XML對象。

  注釋4:將Flash端傳送來的XML字串匯入到XML對象中。

  注釋5:讀取XML對象中//FILE/ID結點的內容。

  注釋6:建立一個資料庫的ADO串連。

  注釋7:構造一個SQL字串,根據傳送來的ID號去查詢資料庫。

  注釋8:如果有合格記錄,讀取相應的記錄。

  注釋9:回複的文章的查詢條件是Fid,所以要重新查詢一下資料庫。

  注釋10:將查詢處理的記錄構造成一個字串。

  注釋11:記錄集的指標下移一步。

  注釋12:構造一個XML格式的字串,並發送到Flash端。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.