shu(id, number) 記錄按鈕數量。<%
Response.Buffer = True
Response.ContentType = "text/plain"
Response.Charset = "gb2312"
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 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath
conn.Open connStr
' 1. 讀取按鈕數量
If action <> "add" And action <> "added" Then
sql = "SELECT number FROM shu WHERE id = 1"
rs.Open sql, conn, 1, 1 ' adOpenKeyset, adLockOptimistic
If Not (rs.EOF And rs.BOF) Then
Response.Write "a=" & rs("number")
Response.Write "&eof=true"
End If
rs.Close
End If
' 2. 刪除按鈕 (實為更新數量為 del 參數值)
If action = "add" Then ' 注意:邏輯上這裡是更新數量
sql = "SELECT number FROM shu WHERE id = 1"
rs.Open sql, conn, 1, 3 ' adLockOptimistic
rs("number") = del
rs.Update
Response.Write "ok=1"
rs.Close
End If
' 3. 保存按鈕數量
If action = "added" Then
sql = "SELECT number FROM shu WHERE id = 1"
rs.Open sql, conn, 1, 3
rs("number") = added
rs.Update
Response.Write "save=1"
rs.Close
End If
conn.Close
Set rs = Nothing
Set conn = Nothing
%>
eof = "false";
a = 0; // 按鈕初始數量
r = random(65500); // 防緩存隨機數
loadVariables("read.asp?action=" + r, "");
if (eof != "true") {
gotoAndPlay("read"); // 循環等待
}
a = Number(a);
if (a == 0 || a < 0) a = 1;
for (i = 1; i <= a; i++) {
_root.attachMovie("m" + i, "m" + i, i + 1); // 庫中需有 m1, m2... 元件
if (i <= 5) {
this["m" + i]._x = 200 + i * this["m" + i]._width;
this["m" + i]._y = 200;
} else if (i <= 10) {
this["m" + i]._x = i * this["m" + i]._width - 50;
this["m" + i]._y = 250;
}
}
stop();
on (release) {
if (a <= 10 && a >= 1) {
a = Number(a) + 1;
_root.attachMovie("m" + a, "m" + a, a + 1);
if (a <= 5) {
this["m" + a]._x = 200 + a * this["m" + a]._width;
this["m" + a]._y = 200;
} else if (a <= 10) {
this["m" + a]._x = a * this["m" + a]._width - 50;
this["m" + a]._y = 250;
}
} else 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; // 限制最大 10
}
}
on (release) {
del = a - 1;
loadVariables("read.asp?action=add", "", "POST"); // 發送新數量
for (i = 1; i <= a; i++) {
removeMovieClip(this["m" + i]); // 清理舊按鈕
}
gotoAndPlay("do_del"); // 跳轉到重新載入幀
}
on (release) {
added = a;
for (i = 1; i <= a; i++) {
removeMovieClip(this["m" + i]);
}
loadVariables("read.asp?action=added", "", "POST"); // 持久化到數據庫
gotoAndPlay("do_save");
}
a=5&eof=true),Flash 自動解析為變量。a 與數據庫 number 字段同步,操作後重新載入確保一致性。random(65500) 附加在請求 URL。這個經典的 ASP+Flash+Access 案例展示了富客戶端 (RIA) 時代的典型架構:客戶端負責豐富交互與狀態維護,服務端負責數據持久化。雖技術棧已過時,但「狀態同步、異步通信、動態 UI 生成、客戶端邏輯與服務端數據分離」的核心思想在現代 Web 應用開發中依然普遍適用。