本文屬於 Flash 技術全盛期(2000 年代初至 2010 年代)的歷史文獻。Adobe 於 2020 年 12 月 31 日正式停止支援 Flash Player,主流瀏覽器已移除 Flash 外掛。現代 Web 開發請採用 HTML5 Canvas/WebGL/WebAssembly、JavaScript 框架(React/Vue/Angular/Svelte)、Web Components 等原生技術。本文保留供維護舊系統參考。
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
width="800" height="600">
<param name="movie" value="MyMovie.swf" />
<param name="quality" value="high" />
<param name="FlashVars" value="init=yes&userId=12345" />
<embed src="MyMovie.swf" quality="high"
pluginspage="https://get.adobe.com/flashplayer/"
type="application/x-shockwave-flash"
width="800" height="600"
FlashVars="init=yes&userId=12345">
</embed>
</object>
FlashVars 需同時在 <param>(IE)與 <embed>(Firefox/Chrome)設定,確保跨瀏覽器相容。
| 技術 | 原理 | 優點 | 缺點 | 適用場景 |
|---|---|---|---|---|
| FlashVars | HTML 參數傳遞,Flash 啟動時一次性讀取 | 簡單、無額外請求 | 僅啟動時可用、資料量受 URL 長度限制、不支援雙向通訊 | 初始化參數、使用者 ID、語系設定 |
| LoadVars | ActionScript 發送 HTTP GET/POST 請求,解析 URL 編碼回應 | 可動態載入、支援簡單雙向 | 手動拼接字串、無型別安全、錯誤處理弱 | 小型設定檔、簡單查詢 |
| Flash Remoting (AMF) | 二進位序列化協議(AMF3),透過 Gateway 呼叫伺服器端 .NET 類別 | 高效能、強型別、支援複雜物件圖、自動序列化 | 需安裝 FluorineFx/WebORB 等 Gateway、除錯較難 | 企業級豐富互聯網應用(RIA)、即時資料推播 |
protected void Page_Load(object sender, EventArgs e) {
string userId = CurrentUser.Id.ToString();
string token = GenerateSecureToken();
string flashVars = $"userId={userId}&token={token}&lang=zh-TW";
litFlashVars.Text = flashVars; // 輸出至 object/embed 標籤
}
[Flash Player] --AMF/HTTP--> [FluorineFx Gateway (ASP.NET)] --.NET Remoting/WCF--> [Business Logic Layer] --ADO.NET/EF--> [Database]
伺服器端需註冊服務:
<fluorine>
<services>
<service id="UserService" class="MyApp.Services.UserService" />
</services>
</fluorine>
ActionScript 呼叫:
var conn:NetConnection = new NetConnection();
conn.connect("https://localhost/gateway.aspx");
var responder:Responder = new Responder(onResult, onFault);
conn.call("UserService.GetProfile", responder, userId);
Flash 曾以向量動畫、跨平台一致性、AMF 高效能二進位協議稱霸 RIA 領域。隨著行動裝置崛起、HTML5 標準成熟、安全性疑慮,Flash 已完成歷史使命。理解其整合模式(FlashVars/LoadVars/Remoting)有助於維護舊系統,更能啟發現代前後端分離架構的設計思維。