Flash 8 新增的 ExternalInterface Class
專門用來與外部環境溝通
比以前的 fscommand、GetProperty、....等好用得多
不過有一個 Bug 可能會讓瀏覽器,或是其它嵌入 Flash Movie 的應用程式當掉
執行環境與條件:
Flash Player main version:8, 9
SWF version:8, 9
ActionScript version:1.0, 2.0
Player type:ActiveX, Plugin
OS:Windows XP, Windows VISTA, Linux
Browser:Firefox, IE6, IE7
在一個 MovieClip Frame Action 或是 onClipEvent 上
呼叫 ExternalInterface.addCallback 註冊 callback function
然後將該 MovieClip 加到 _root timeline frame 1
在 _root timeline 建立關鍵影格 frame 2 並加上 frame action : stop();
於 frame 2 移除該 MovieClip
這樣 Flash Movie 便會停在 frame 2
此時外部環境 JavaScript 呼叫先前註冊過的 function
便會讓瀏覽器或是應用程式當掉
ActionScript 1.0 ExternalInterface Bug Demo Code:
onClipEvent (load) {
import flash.external.*;
var callByJs = function () {
trace("callByJs");
};
ExternalInterface.addCallback("callByJs",null,callByJs);
}
JavaScript Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ExternalInterface Crash Demo</title>
<script type="text/javascript">
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
function doCallAS() {
var crashMovie = isInternetExplorer ? document.all.crashMovie : document.crashMovie;
crashMovie.callByJs();
}
</script>
</head>
<body>
<p>
<input type="submit" name="button" id="button" value="JS call AS" onClick="doCallAS();" />
</p>
<p>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,28,0"
width="300" height="200" id="crashMovie">
<param name="movie" value="ExternalCrashDemo.swf" />
<param name="allowScriptAccess" value="always" />
<embed src="ExternalCrashDemo.swf" width="300" height="200"
pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"
type="application/x-shockwave-flash" name="crashMovie"
allowscriptaccess="always"></embed>
</object>
</p>
</body>
</html>
ExternalInterface Crash Bug Demo Page
以上的 Bug 至少會在以下 Flash Player 版本發生:
Flash Player 8.0.33.0
Flash Player 9.0.115.0
Flash Player 9.0.124.0
Flash Player 10.0.12.10
Flash Player 10.0.22.87








