现在的位置: 首页 > 综合 > 正文

用Flash和XML构建论坛实例(2)

2013年04月10日 ⁄ 综合 ⁄ 共 9671字 ⁄ 字号 评论关闭
三、查看正文

  查看正文,即是在服务器端接收从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端。

抱歉!评论已关闭.