Flash+asp+xml Message This tutorial

Source: Internet
Author: User
Tags date format empty modify connect variables variable trim
asp+|xml| Tutorial

Demo Address

source File Download

Before downloading to the local or upload to the space, please go to the background to modify the parameters set inside the address, and then test!

If your machine or server does not support FSO, please manually modify the address inside the Url.xml file!

Main part of ASP:

Page.asp (N records passed to flash n pages)

<% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>
<% show_page = 9 ' Records per page display
db = "Data/data.mdb" Database storage directory
'-Connecting to the database
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath (db)
'-----------------------------------------------------------------------
' Use: Convert UTF-8 encoded Chinese characters into GB2312 codes, compatible with English and digital!
function Encodestr (str)
Dim i
Str=trim (str)
Str=replace (str, "'", "" "")
Str=replace (Str,vbcrlf&vbcrlf, "</p><p>")
Encodestr=replace (Str,vbcrlf, "<br>")
End Function
' Use: Convert UTF-8 encoded Chinese characters into GB2312 codes, compatible with English and digital!
Function Uni (Chinese)
For j = 1 to Len (Chinese)
A=mid (Chinese, J, 1)
Uni= Uni & "& #x" & Hex (AscW (a)) & ";"
Next
End Function%>
<%
' If flash passes the variable
If Request ("action") = "ShowPage" Then
' Open the Record
Sql= "SELECT * from Gbook ORDER BY id DESC"
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open sql,conn,1,1
'---------------Paging start
If not rs.eof then
' If there is a record
Rs. PageSize = Show_page
Total=rs. RecordCount ' Total number of records
Maxpage=rs. PageCount ' divided several pages
Page=request ("page") ' current page
If not isnumeric (page) or page= "" Then
Page=1
Else
Page=cint (page)
End If
If Page<1 Then
Page=1
ElseIf Page>maxpage Then
Page=maxpage
End If
Rs. Absolutepage=page
Else
' If there's no record
Total=0
Maxpage=0
Page=0
Out= ""
wujilu= "1"
' Pass the Wujilu variable to flash, let flash know that there is no record and then make the appropriate action
' Output XML file format
Response.Write "<?xml version= ' 1.0 ' encoding= ' utf-8 '?> '"
Response.Write "<gbook total= '" &total& "' maxpage= '" &maxpage& "' page= '" &page& "' wujilu= '" &wujilu& "' ></gbook>"
Session.codepage= "936"
End If
'---------------pagination ends

'---------------Open PageSize record start
If not rs.eof then
' If there is a record
For I=1 to Rs. PageSize
PAGE_ID=RS ("id")
Page_name=uni (RS ("name"))
If Len (rs ("title")) > Then ' intercept character
Page_title=left (RS ("title"), & "..." Intercepting characters
Else
Page_title=rs ("title")
End If
Page_title=uni (Page_title)
Page_date=rs ("date")
out=out& "<info page_id= '" &page_id& "' page_name= '" &page_name& "' page_title= '" &page_ title& "' page_date= '" &page_date& "'/>"
Rs.movenext
If Rs. EOF Then
I=i+1
Exit for
End If
Next
End If
'---------------Open PageSize record end
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing ' Frees resources
' Output paging information, XML format
Response.Write "<?xml version= ' 1.0 ' encoding= ' utf-8 '?> '"
Response.Write "<gbook total= '" &total& "' maxpage= '" &maxpage& "' page= '" &page& "' >" &out& "</gbook>"
Session.codepage= "936"
End If
%>

Show.asp (information passed to flash single record)

<% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>
<%
Show_page = 9 ' Records per page display
db = "Data/data.mdb" Database storage directory
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath (db)
'-----------------------------------------------------------------------
' Use: Convert UTF-8 encoded Chinese characters into GB2312 codes, compatible with English and digital!
function Encodestr (str)
Dim i
Str=trim (str)
Str=replace (str, "'", "" "")
Str=replace (Str,vbcrlf&vbcrlf, "</p><p>")
Encodestr=replace (Str,vbcrlf, "<br>")
End Function
Function Uni (Chinese)
For j = 1 to Len (Chinese)
A=mid (Chinese, J, 1)
Uni= Uni & "& #x" & Hex (AscW (a)) & ";"
Next
End Function
'------------------------------------------------------------
%>
<%
If Request ("action") = "show" Then
' Turn on the record show_id message for Flash.
Sql= "SELECT * from Gbook where id=" &request ("show_id")
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open sql,conn,1,1
' Uni parameter, is to convert GB code into UTF-8 code, otherwise flash will be garbled
Show_name=uni (RS ("name"))
Show_id=uni (RS ("id"))
Show_title=uni (RS ("title"))
If RS ("email") <> "then"
Show_email=uni (RS ("email"))
End If
If RS ("QQ") <> "then"
Show_qq=uni (RS ("QQ"))
End If
Show_content=uni (RS ("content"))
Show_date=uni (RS ("date"))
out=out& "<info show_name= '" &show_name& "' show_id= '" &show_id& "' show_title= '" &show_ title& "' show_email= '" &show_email& "' show_qq= '" &show_qq& "' show_content= '" &show_content & "' show_date= '" &show_date& "/>"
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
' Output XML format
Response.Write "<?xml version= ' 1.0 ' encoding= ' utf-8 '?> '"
Response.Write "<gbook>" &out& "</gbook>"
End If
%>

Add.asp (Flash to ASP add record)

<%
Show_page = 9 ' Records per page display
db = "Data/data.mdb" Database storage directory
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath (db)
'-----------------------------------------------------------------------
' Use: Convert UTF-8 encoded Chinese characters into GB2312 codes, compatible with English and digital!
function Encodestr (str)
Dim i
Str=trim (str)
Str=replace (str, "'", "" "")
Str=replace (Str,vbcrlf&vbcrlf, "</p><p>")
Encodestr=replace (Str,vbcrlf, "<br>")
End Function
Function Uni (Chinese)
For j = 1 to Len (Chinese)
A=mid (Chinese, J, 1)
Uni= Uni & "& #x" & Hex (AscW (a)) & ";"
Next
End Function
'------------------------------------------------------------
%>
<%
Session.codepage= "65001"
If ENCODESTR (Request ("action") = "Add" Then ' if the variable that flash passes over is add
If ENCODESTR (Request ("w_name") = "then" if W_name equals null
Cuowu= "n"
Response.Write "&addok=" +cuowu '
ElseIf Encodestr (Request ("w_title") = "Then ' if the title is empty
cuowu= "T"
Response.Write "&addok=" +cuowu
ElseIf encodestr ("w_content") = "Then ' If the message content is empty
Cuowu= "C"
Response.Write "&addok=" +cuowu
End If
If cuowu= "" Then ' if name, title, message content not empty
Sql= "SELECT * from Gbook"
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open sql,conn,3,3
Rs.addnew ' increased record
RS ("name") =encodestr (Request ("W_name"))
RS ("title") =encodestr (Request ("W_title"))
If ENCODESTR (Request ("w_email") = "" Then
RS ("email") =null
Else
RS ("email") =encodestr (Request ("W_email"))
End If
If ENCODESTR (Request ("w_qq") = "" Then
RS ("QQ") =null
Else
RS ("QQ") =encodestr (Request ("W_QQ"))
End If
RS ("content") =encodestr (Request ("W_content"))
RS ("date") =date ()
Rs.update
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
Response.Write "&addok=ok" ' Return to Flash message success
End If
End If
Session.codepage= "936"
%>

Flash section:

Message list

function showpage ()//defining functions
{
function Titlemenu ()
{
Gbtitle.attachmovie ("Title_mc", "TITLE_MC" + I, I);
gbtitle["TITLE_MC" + i]._y = position of I;//MC
gbtitle["TITLE_MC" + i].page_id = gb[i].attributes.page_id;//title_mc dynamic text shows the variables from ASP
page_id=gb[i].attributes.page_id;
gbtitle["TITLE_MC" + i].page_title = gb[i].attributes.page_title;
gbtitle["TITLE_MC" + i].page_date = gb[i].attributes.page_date;
gbtitle["TITLE_MC" + i].page_name = gb[i].attributes.page_name;
i++;
if (i >= ntotal)//If the record is greater than the record displayed on each page
{
Clearinterval (Ninterval);
}//End If
}//End Function
Total= PageXML.firstChild.attributes.total;
Maxpage = PageXML.firstChild.attributes.maxpage;
page = PageXML.firstChild.attributes.page;
Tpage = "" "+ page +"/"+ maxpage +" page altogether "+ Total +" message ";
GB = PageXML.firstChild.childNodes;
Ntotal = gb.length;//A few nodes-a total of several records
var ninterval = setinterval (Titlemenu, 50);//Deferred loading
This.createemptymovieclip ("Gbtitle", 1);//Create an empty MC
gbtitle._x = 10;
Gbtitle._y = 70;
var i = 0;
}//End Function
Stop ();
Pagexml = new XML ();//Create Object
Pagexml.ignorewhite = true;//Ignore spaces
Pagexml.load (gbookurl+ "page.asp?action=showpage&page=" +page + "&temp=" + math.random () * Number (GetTimer ())) ;
Pagexml.onload = function (Success)
{
if (success)//if Read is successful
{
ShowPage (1);
If the load succeeds
Xiaoxi = "Loading data, please wait ...";
_root.xiaoxikuang.gotoandplay ("WU");
_root.jindutiao.gotoandplay ("WU");
gotoAndPlay (76);
}
Else
{
gotoAndPlay ("error");
If the load fails
_root.xiaoxikuang.xiaoxi = "Unable to connect to database, check network connection";
}//End If
};//End Function

Read a single record

Gbtitle.removemovieclip ()//Uninstall message list
_global.zhen= "read";
function Page (index)
{
Passing variables from ASP to dynamic text
SHOW_ID = "ID:" +READ[INDEX].ATTRIBUTES.SHOW_ID;
Show_name = "message person:" +READ[INDEX].ATTRIBUTES.SHOW_NAME;
Show_title = "title:" +read[index].attributes.show_title;
SHOW_QQ = "QQ:" +READ[INDEX].ATTRIBUTES.SHOW_QQ;
Show_email = "e-mail:" +read[index].attributes.show_email;
Show_content = read[index].attributes.show_content;
Show_date = "Published time:" +read[index].attributes.show_date;
}//End Function
Showxml = new XML ();
Showxml.ignorewhite = true;
Showxml.load (gbookurl+ "show.asp?action=show&show_id=" + go_id + "&temp=" + math.random () * Number (GetTimer ())) ;
Showxml.onload = function (Success)
{
if (success)
{
If the load succeeds
_root.xiaoxikuang.xiaoxi = "Loading data, please wait ...";
Read = ShowXML.firstChild.childNodes;
Total = Read.length;
Page (0);
gotoAndPlay (79);
}
Else
{
gotoAndPlay ("error");
If the load fails
_root.xiaoxikuang.xiaoxi = "Unable to connect to database, check network connection";
}//End If
};//End Function

Write a record

function SendData ()
{
Pass the contents of the dynamic text to Send_var
Send_var.w_name = _root.w_name;
SEND_VAR.W_QQ = _ROOT.W_QQ;
Send_var.w_email = _root.w_email;
Send_var.w_title = _root.w_title;
Send_var.w_content = _root.w_content;
Send_var.sendandload (gbookurl+ "Add.asp?action=add", Load_var, "post");
}//End of the function

Send_var = new Loadvars ();
Load_var = new Loadvars ();
Fabiao.onrelease = SendData;
Load_var.onload = function ()
{

if (this.addok== "OK")
{
_root.xiaoxikuang.xiaoxi = "message successful!";
gotoAndPlay ("wok");
}
if (this.addok== "n")
{
_root.xiaoxikuang.xiaoxi = "Name cannot be empty!";
gotoAndPlay ("Werror");
}
if (this.addok== "T")
{
_root.xiaoxikuang.xiaoxi = "title cannot be empty!";
gotoAndPlay ("Werror");
}
if (this.addok== "C")
{
_root.xiaoxikuang.xiaoxi = "message content can not be empty!";
gotoAndPlay ("Werror");
}

};//end Load_var Fun
Chongzhi.onrelease = function ()//reset button
{
_root.w_name = "";
_ROOT.W_QQ = "";
_root.w_email = "";
_root.w_title = "";
_root.w_content = "";
}
Stop ();

The main use of the code on these, but also the background management function added in the flash inside, but because I was working, no time, so I made a simple message!



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.