ASP部分:
<%
added=request("added")
del=request("del")
action=request.QueryString("action")
set conn=server.createObject ("adodb.connection")
set rs=server.createObject ("adodb.recordset")
dbpath=server.MapPath ("db1.mdb")
connstr="Driver={Microsoft Access Driver (*.mdb)};dbq="&dbpath
conn.Open connstr
if (action <> "add" and action <>"added") then
'下面是讀取數據庫信息部分
sql="select * from shu where id=1"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
else
Response.Write "a=" & (RS("number"))
response.Write "&eof=true"
end if
end if
%>
<%
'下面部分為刪除按扭信息部分
if (action="add") then
sql="select * from shu where id=1"
rs.Open sql,conn,1,3
rs("number")=del
rs.update
response.write "ok=1"
rs.close
end if
%>
<%
'下面的部分是保存按扭信息部分
if (action="added") then
sql="select * from shu where id=1"
rs.Open sql,conn,1,3
rs("number")=added
rs.update
response.write "save=1"
rs.close
end if
%>
FLASH部分:
第一部分是初始化變量:
eof = "false";
a=0; //按扭的初始數量
r = random(65500);
loadVariables("read.asp?action=" add r, "");//添加隨機數的目的是防止不同浏覽器不無法刷新變量的(不過可能是畫蛇添足,哈哈)第9貞:
if (eof ne "true") {
gotoAndPlay("read");
}
判斷是否讀取數據成功!
第十貞:
a = Number(a);
if (a == 0 or a<0) {
a = 1;
for (i=1; i<=a; i++) {
_root.attachMovie("m"+i, "m"+i, i+1);
if (i<=5) {
eval("m"+i)._x = 200+i*eval("m"+i)._width;
eval("m"+i)._y = 200;
}
if (i>5 and i<=10) {
eval("m"+i)._x = i*eval("m"+i)._width-50;
eval("m"+i)._y = 250;
}
}
} else {
for (i=1; i<=a; i++) {
_root.attachMovie("m"+i, "m"+i, i+1);
if (i<=5) {
eval("m"+i)._x = 200+i*eval("m"+i)._width;
eval("m"+i)._y = 200;
}
if (i>5 and i<=10) {
eval("m"+i)._x = i*eval("m"+i)._width-50;
eval("m"+i)._y = 250;
}
}
}
stop();
//根據數據庫中按扭數量"a"的大小添加按扭,並且以5*2的順序進行排序!加載按扭:
on (release) {
if (a<=10 and a>=1) {
a =Number(a)+1;
trace(a);
_root.attachMovie("m"+a, "m"+a, a+1);
if (a<=5) {
eval("m"+a)._x = 200+a*eval("m"+a)._width;
eval("m"+a)._y = 200;
}
if (a>5 and a<=10) {
eval("m"+a)._x = a*eval("m"+a)._width-50;
eval("m"+a)._y = 250;
}
}
if (a>10) {
_root.aa.attachMovie("wrong", "wrong", 1000);
this.wrong._width = 600;
this.wrong._height = 400;
this.wrong._x = 225;
this.wrong._y = 200;
a=10
}
}
根據A的數量進行在次加載按扭(這裡只采用FLASH內部加載),如果超按扭數量超過10個,則停止加載並出現警告!刪除按扭部分:
on (release) {
del = a-1;
loadVariables("read.asp?action=add", "", "POST");
for(i=1;i<=a;i++){
removeMovieClip(eval("m"+i));
}
gotoAndPlay("do_del");
}
//確定刪除後A的值,並將其傳送個ASP!但是此處需要清理FLASH內部A的數量,以防止FLASH內部沒有刷新而造成刪除後A的數量減少,但按牛數量沒有減少的情況!保存按扭部分:
on (release) {
added = a;
for(i=1;i<=a;i++){
removeMovieClip(eval("m"+i));
}
loadVariables("read.asp?action=added", "", "POST");
gotoAndPlay("do_save");
}//將A的數值傳給ASP 然後存到數據庫中,此處也清空了FLASH內部A的值,原因同上!