Flash與資料庫的串連方法與代碼

來源:互聯網
上載者:User

確切地說..flash是不可以直接與資料庫連接的.只能是通過ASP...所以呢.首先,先在ASP裡編寫好串連資料庫的語句 複製代碼 代碼如下:<%
dim cn
dim connstr
dim db
db="asp.mdb"
Set cn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
cn.Open connstr
%>

儲存為cn.asp檔案;
第二步;就編寫一個讀取資料庫資料的ASP檔案嘍...
複製代碼 代碼如下:<!--#include file="cn.asp"-->
<%
set rs=server.createobject("adodb.recordset")
rs.open "select * from class ",cn,3,3
for i=1 to rs.recordcount
if not rs.eof then
totalClass=totalClass&rs("Class")&","
totalLink=totalLink&rs("classlink")&","
rs.movenext()
end if
next
response.write ("flashClass="&totalClass&"&")
response.write ("flashLink="&totalLink&"&")
'注意這個寫格式.多個參數得用&這個來串連.有些人會忽略到這一點.導致在flash不能寫出資料來. %>

將這個檔案儲存體為:write.asp
第三步;回到flash那裡來編寫語句.把write.asp檔案載入進來.
第一幀:
System.useCodepage=true;
var newload = new LoadVars();//如果不是很瞭解這個LoaVars,可以去查一下那個flash裡面的協助文檔
newload.load("write.asp");
newload.onLoad = function(success) {
if (success) {
_root.gotoAndStop(2);//當檔案被載入完成後,執行第二幀.
}
};
stop();//這裡要注意.如果不用停止.假設檔案還沒有載入完就執行第二幀...而在第二幀是在flash裡讀取資料的.那就導致讀不出資料
第二幀:
_root.name.text = newload.flashClass;//下面兩句是讀取資料的.
_root.link.text = newload.flashLink;
_root.bt._visible = false;//是一個影片的名字,裡面放有一個動態文本bttext
//現在就把資料放到數組中去....
var aspclass = newload.flashClass;
var link = newload.flashLink;
var Aclass = new Array();
var Blink = new Array();
for (i=0; i<aspclass.length; i++) {
Aclass = aspclass.split(",", i);
Blink = link.split(",", i);
}
for (i=0; i<Aclass.length-1; i++) {
//for (i=1; i<6; i++) {
_root.bt.duplicateMovieClip("bt"+i, i);
_root["bt"+i]._y = i*30;
_root["bt"+i]._x = 5;
_root["bt"+i].url = Blink;
_root["bt"+i].bttext.text = Aclass;
_root["bt"+i].onRelease = function() {
_root.link2.text = this.url;
getURL("http://"+this.url,"_blank");
};
}

聯繫我們

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