Let's take a look at the functions of the Forum. you can log on to the Forum, view the topic, view the body, post a new topic, reply to the topic, delete the topic, and manage permissions. You can make some modifications based on your needs, you can implement a forum with complete functions. The following describes the functions of the Forum one by one in sequence. Each introduction is divided into three parts: "transmitted XML", "Flash", and "Asp.
I. Login
Login sends the user name and password to the server in XML format, and the server returns the verification results in XML format.
A. Passed XML
XML is the XML string transmitted between the server and Flash, that is, the communication packet in the general sense.
1. Request Message
2. Response Message
B. Flash end
1. Create a New Flash file in Flash MX 2004 and add the Statement on the ActionScript Panel of the first frame of the scenario:
Stop ();
2. In the first frame scenario, use a text tool to pull two text boxes of the "Input type" type, and set the variable name var to "username" and "pwd" respectively ", this is used to enter the user name and password.
3. Create a New Button and drag it to the first frame, as shown in position 1. Add the following statement to the panel of the Button:
|
On (release ){ LoginXml = new XML (); // comment 1 LoginElement = loginXml. createElement ("LOGIN"); // comment 2 // Name node NameElement = loginXml. createElement ("USERNAME"); // comment 3 NameNode = loginXml. createTextNode ("name"); // comment 4 NameNode. nodeValue = _ root. username; // comment 5 NameElement. appendChild (nameNode); // Note 6 // Pwd node PwdElement = loginXml. createElement ("PWD"); // comment 7 PwdNode = loginXml. createTextNode ("pwd "); PwdNode. nodeValue = _ root. pwd; PwdElement. appendChild (pwdNode ); LoginElement. appendChild (nameElement); // comment 8 LoginElement. appendChild (pwdElement); // comment 9 LoginXml. appendChild (loginElement); // Comment 10XmlRepley = new XML (); // comment 11 XmlRepley. onLoad = onLoginReply; // comment 12 Function onLoginReply (success ){ If (success) {// note 13 If (xmlRepley. firstChild. firstChild. attributes. right = "1") {// comment 14 _ Root. gotoAndPlay ("main ") } Else { _ Root. username = "Logon Failed "; } } } LoginXml. sendAndLoad ("http: // localhost/xmlbbs/login. asp", xmlRepley); // comment 15 } |
Note 1: Create an XML object to be sent to the server.
NOTE 2: Create a LOGIN Node object.
NOTE 3: Create a USERNAME Node object. Note that Text content cannot be placed directly in the Element Object. Text content must be placed in the Text Node object. For details, see the content in XML. createElement () and XML. createTextNode () in the Flash help file.
Note 4: Create a Text Node object to place the Text content of the USERNAME Node.
Note 5: assign values to the Text Node.
Note 6: insert the created Text Node to the USERNAME Node object.
Note 7: Create a PWD Node object and a Text Node respectively, and insert the Text Node to the PWD Node object.
Note 8: insert the USERNAME Node object into the LOGIN Node object.
Note 9: insert the PWD Node object to the LOGIN Node object.
Note 10: insert the LOGIN Node object to the created XML object to construct a complete XML object. Note that the XML object is built from the very beginning.
Note 11: Create an XML object, which is used to place the received XML object.
Note 12: Set the response function for receiving XML objects, which is triggered when the server returns an XML object.
Note 13: success indicates whether the XML object is returned from the server.
Note 14: Determine whether the node attribute in the returned XML object meets the requirements.
Note 15: The sendAndLoad () function is used to send XML objects from Flash to the server and receive XML objects returned from the server.
C. Asp end
Create an Asp file named login. asp. Enter the following content:
|
<% Set MyFileObject = Server. CreateObject ("Scripting. FileSystemObject") 'comment 1 Set MyTextFile = MyFileObject. CreateTextFile ("G: \ writing \ flashxmlbbs \ login. xml", 8, TRUE) 'comment 2 MyTextFile. WriteLine (Request. Form) 'comment 3 Set objDom = server. CreateObject ("microsoft. xmldom") 'comment 4 ObjDom. loadxml (Request. Form) 'comment 5 Set objname = objdom.doc umentElement. SelectSingleNode ("// LOGIN/USERNAME") 'comment 6 Username = objname. text' comment 7 Set objpwd = objdom.doc umentElement. SelectSingleNode ("// LOGIN/PWD") 'comment 8 Pwd = objpwd. text Righ = "-1" 'Judge Set conn = Server. CreateObject ("ADODB. Connection ") Conn. open "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & Server. MapPath ("/xmlbbs. mdb") 'comment 9 Set rs = Server. CreateObject ("ADODB. Recordset") 'comment 10 StrSql = "select * from UserInfo where username = '" & username & "' and userpwd = '" & pwd & "'" 'comment 11 Rs. open strSql, conn, 1, 1' comment 12 If not (rs. bof and rs. eof) then' comment 13 Righ = rs ("userright") 'comment 14 Else Righ = "0" End if Rs. close Conn. close 'Back Response. write ("<LOGIN> <USRENAME name =" & username & "right =" "& righ &" ">" & username & "</USERNAME> </LOGIN> ") 'comment 15 %> |
Note 1: Use the FileSystemObject component to create a file object and write the content transmitted during communication in the file for debugging.
NOTE 2: Modify the file path as needed.
NOTE 3: write all the content transmitted by Request. Form in the file, leaving traces on the server side.
Note 4: Create an XML object. You can find more information about XML operations in the ms xml package.
Note 5: Use the loadxml () function to import the XML format string transmitted by the Flash end.
Note 6: Create an object for the USERNAME node.
Note 7: Get the content of the USERNAME node.
Note 8: Create an object of the PWD node and obtain the content of the PWD node.
Note 9: Create An ADO connection to the database. Access 2000 is used here. For the format of the database, see the appendix below. Pay attention to the database storage location.
Note 10: Create a database Recordset.
Note 11: Construct an SQL string based on the obtained user name and password.
Note 12: query the database based on the constructed SQL string.
Note 13: Determine whether the user name and password are correct.
Note 14: the username and password are correct and the database permissions are obtained.
Note 15: Construct an XML string and write it to the Flash end using the write function.
Ii. view the topic
To view the topic, the Flash client sends a request to the server. The server sends the topic stored in the database to the Flash server in XML format.
A. Passed XML
1. Request Message
2. Response Message
|
<TITLE title1 = "TITLE 1" id1 = "Number 1" title2 = "TITLE 2" id2 = "Number 2" title3 = "TITLE 3" id3 = "Number 3" title4 = ""Title 4" id4 = "Number 4" title5 = "Title 5" id5 = "Number 5" title6 = "Title 6" id6 = "Number 6" title7 = "title 7" id7 = "7" title8 = "Title 8" id8 = "8" title9 = "Title 9" id9 = "9" title10 = "Title 10" id10 = "Number 10 "> </TITLE> |
B. Flash end
1. "Insert key frame" on the second frame of the scenario, name this frame as "main", and add the following statement on the Action Script panel of this frame:
FileNowId = "0 "; FileId1 = "0 "; FileId2 = "0 "; FileId3 = "0 "; FileId4 = "0 "; FileId5 = "0 "; FileId6 = "0 "; FileId7 = "0 "; FileId8 = "0 "; FileId9 = "0 "; FileId10 = "0 "; Stop (); |
Note: The preceding variables are set to save the ID number returned from the server.
2. In the second frame scenario, use the text box tool to pull ten text boxes and set the types to "Input Type ", the variables var are set to "title1", "title2", "title3", "title4", "title5", "title6", "title7", "title8", and "title9" and "title10 ".
3. Add an update Button in the second frame to update the topic. Add the following statement on the Action Script Panel of the Button:
|
On (release ){ TitleXml = new XML (); // comment 1 TitleElement = titleXml. createElement ("TITLE"); // comment 2 LoginElement. appendChild (titleElement); // comment 3 TitleXml. appendChild (titleElement ); TitleRepley = new XML (); // comment 4 TitleRepley. onLoad = onTitleReply; // comment 5 Function onTitleReply (titlesuccess ){ If (titlesuccess) {// Note 6 _ Root. title1 = titleRepley. firstChild. attributes. title1; // comment 7 _ Root. title2 = titleRepley. firstChild. attributes. title2; _ Root. title3 = titleRepley. firstChild. attributes. title3; _ Root. title4 = titleRepley. firstChild. attributes. title4; _ Root. title5 = titleRepley. firstChild. attributes. title5; _ Root. title6 = titleRepley. firstChild. attributes. title6; _ Root. title7 = titleRepley. firstChild. attributes. title7; _ Root. title8 = titleRepley. firstChild. attributes. title8; _ Root. title9 = titleRepley. firstChild. attributes. title9; _ Root. title10 = titleRepley. firstChild. attributes. title10; _ Root. fileId1 = titleRepley. firstChild. attributes. id1; // comment 8 _ Root. fileId2 = titleRepley. firstChild. attributes. id2; _ Root. fileId3 = titleRepley. firstChild. attributes. id3; _ Root. fileId4 = titleRepley. firstChild. attributes. id4; _ Root. fileId5 = titleRepley. firstChild. attributes. id5; _ Root. fileId6 = titleRepley. firstChild. attributes. id6; _ Root. fileId7 = titleRepley. firstChild. attributes. id7; _ Root. fileId8 = titleRepley. firstChild. attributes. id8; _ Root. fileId9 = titleRepley. firstChild. attributes. id9; _ Root. fileId10 = titleRepley. firstChild. attributes. id10; } } TitleXml. sendAndLoad ("http: // localhost/xmlbbs/title. asp", titleRepley); // comment 9 } |
Note 1: Create an XML object for sending.
NOTE 2: Create a TITLE Node object.
NOTE 3: add the TITLE Node object to the XML object.
Note 4: Create an XML object for the response.
Note 5: Set the onLoad function to respond to the XML object.
Note 6: titlesuccess indicates whether to return XML objects from the server.
Note 7: display the returned title attributes in the text box of the scenario.
Note 8: Save the returned ID number in the variable of the scenario.
Note 9: The sendAndLoad () function is used to send XML objects from Flash to the server and receive XML objects returned from the server.
C. Asp end
Create an Asp file named title. asp. Enter the following content:
<%
Set MyFileObject = Server. CreateObject ("Scripting. FileSystemObject") 'comment 1
Set MyTextFile = MyFileObject. CreateTextFile ("G: \ writing \ flashxmlbbs \ login. xml", 8, TRUE)
MyTextFile. WriteLine (Request. Form) 'comment 2
Set objDom = server. CreateObject ("microsoft. xmldom") 'comment 3
ObjDom. loadxml (Request. Form) 'comment 4
Set objname = objdom.doc umentElement. SelectSingleNode ("// TITLE") 'comment 5
'Judge
Set conn = Server. CreateObject ("ADODB. Connection ")
Conn. open "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & Server. MapPath ("/xmlbbs. mdb") 'comment 6
Set rs = Server. CreateObject ("ADODB. Recordset ")
StrSql = "select * from fileinfo"
Rs. open strSql, conn, 1, 1' comment 7
TempNum = 1
StrResult = ""
Do until tempNum = 11' comment 8
If rs. eof then' comment 9
Exit do
End if
StrResult = strResult & "title" & tempNum & "=" & rs ("title ") & "&" id "& tempNum &" = "& rs (" ID ") &" 'comment 10
TempNum = tempNum + 1
Rs. movenext 'comment 11
Loop
Rs. close
Conn. close
'Back
Response. write ("<TITLE" & strResult & "> </TITLE>") 'comment 12
%>
Note 1: create a file object.
NOTE 2: Write the XML string sent from Flash in a temporary file.
NOTE 3: Create an XML object.
Note 4: import the XML string sent from Flash to an XML object.
Note 5: Create a TITLE Node object.
Note 6: Create An ADO connection to the database and open the database.
Note 7: Construct an SQL string to query qualified records in the database. Note 8: records in the Recordset record set are read cyclically.
Note 9: if the end of the record set is reached, exit the loop.
Note 10: splice the records read from the record set into a string in the format.
Note 11: Move the pointer in the Recordset record set one step down.
Note 12: Send the string constructed in the loop to the Flash end.