本文解释如何连接flash到一个Access数据库,flash是不能直接与数据库交换信息的,我们必须借助asp(或其它服务器端的脚本语言)。ASP可以访问数据库,并可将信息传递给FLASH。下面我将建立一个简单的flash地址簿来演示这一过程。
注:要完成本教程您的PC上需要有
1、 flash 5(或 flash mx )
2、 (Internet information Services 4.0(或IIS5.0)
3、 Microsoft Access
一、预备知识:
flash中的脚本命令:
loadVariables(url,location);
通过loadvariable方法可以实现与ASP传递信息。
Loadvariables命令从URL所指的文件内容中获得信息,并将这些信息赋给FLASH中的变量。
其中URL所指的文件内容必须为MIME格式或者为URL格式编码的格式。
例如:URL所指定的页包含如下内容:
Var1=Test&Var2=Demo
Flash中变量Var1的值被赋予“test”,Var2的值被赋予“Demo”。
二、数据库设计:
建立只包含一个表:Contacts的数据库addressbook.mdb。Contacts表的结构如下:
Field nameype Size
ContactID AutoNumber -
Name Text 50
Telephone Text 50
City Text 50
Notes Memo -
三、asp设计:
用编辑软件制作名为:getdetails.asp
getdetails.asp代码如下:
<%
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open "Driver=Microsoft Access Driver (*.mdb);DBQ=" &
Server.MapPath("AddressBook.mdb")
Set cmdTemp = Server.CreateObject("ADODB.Command")
Set rstContacts = Server.CreateObject("ADODB.Recordset")
cmdTemp.CommandText = "Select * From Contacts"
cmdTemp.CommandType = 1
Set cmdTemp.ActiveConnection = DataConn
rstContacts.Open cmdTemp, , 1, 3
rstContacts.Move CLng(Request("Record"))
Response.write "Name=" & Server.URLEncode(rstContacts("Name")) & "&"
Response.write "Telephone=" & Server.URLEncode(rstContacts("Telephone")) & "&"
Response.write "City=" & Server.URLEncode(rstContacts("City")) & "&"
Response.write "Notes=" & Server.URLEncode(rstContacts("Notes")) & "&"
Response.write "TotalRecords=" & rstContacts.RecordCount
rstContacts.Close
DataConn.Close
%>
在浏览器中查看getdetails.asp?record=2,结果如下:
Name=Steve+Tipson&Telephone=%2B44+2123+121+1245&City=Birmingham&Notes=Artist+in+waiting%2E&TotalRecords=4
四、flash设计
1、在flash中建立一个名为AddressBook的movie clip,用于地址簿,它包含五个动态文本框用于显示数据库信息,两个按钮(一个左箭头、一个右箭头)用于数据库记录导航,此MC大致如下图如示:
左箭头上的Actionscript为:
on (release)
{
CurrentRecord--;
if (CurrentRecord == -1)
CurrentRecord = TotalRecords-1;
loadVariables ("getdetails.asp?Record=" add String(CurrentRecord), this);
}
右箭头上的Actionscript为:
on (release)
{
CurrentRecord++;
if (CurrentRecord == TotalRecords)
CurrentRecord = 0;
loadVariables ("getdetails.asp?Record=" add String(CurrentRecord), this);
}
2、将movie clip“ AddressBook”放入主场景中。
在MC上加actionscript为:
onClipEvent(data)
{
strName = Name;
strTelephone = Telephone;
strCity = City;
strNotes = Notes;
strPosition = "Record " add String(CurrentRecord+1) add " of " add String(TotalRecords);
}
onClipEvent(load)
{
CurrentRecord = 0;
loadVariables ("getdetails.asp?Record=0", this);
}
整个制作过程结束,你可以测试你的flash了!
This blogger is recording some code samples,technical skill of java,.Net,javascript, css, html for myself use. All articles are coming from my own experience and my collections which are from internet world. If you find any material have copy right issue please leave a comment to me. I will delete it immediately. These articles are writing in English or Chinese. Hope these information can help other technical guys. Thanks for reading.
Subscribe to:
Post Comments (Atom)
-
If you get "This page calls for XML namespace http://richfaces.org/a4j declared with prefix a4j but no taglibrary exists for that names...
-
Method 1: import oracle.sql.*; public class JClob { String tableName = null; // String primaryKey = null; // String primaryValue = null; // ...
-
1.HTTP-binding(ServiceMix) 1.4 各组件间传递消息流的过程如下: 1. HttpClient : Http 客户端运行一个独立的 Java 客户端程序,通过其中的 URLConnection 类连接到 http://...
No comments:
Post a Comment