正如 Pete 所说,ExternalInterface 无疑是在 SWF 和周围的 HTML 页面之间进行函数调用所需要的。
您还可以使用swfobject 进行跨浏览器兼容的 SWF 动态嵌入/加载到页面中。
我在此处对您正在寻找的两个功能做了一个小演示:http://akineticblog.com/fl/ExtIntDemo/index.html
AS3 代码是:
import flash.external.ExternalInterface;
var recording:Boolean = false;
//These are two TextFields instantiated on the stage as visual indicators
recordingTF.visible = false;
notRecordingTF.visible = true;
function recording_toggle():void {
recording = ! recording;
//Your actual record start/stop code would go here//
recordingTF.visible = recording;
notRecordingTF.visible = ! recording;
}
if (ExternalInterface.available) {
//This registers the AS3-side function to the JS-side reference
ExternalInterface.addCallback("recording_toggle", recording_toggle);
}
对于HTML/JS端,可以查看上面链接的页面源码,但主要部分是:
function swf_load() {
swfobject.embedSWF("ExtIntDemo.swf", "flashMovie", "500", "250", "10.1", "swf/expressinstall.swf", flashvars, params, attributes);
};
- 在您想要加载 SWF 时调用,将 div 替换为 id 'flashMovie'。
还有:
<button onclick="flashMovie.recording_toggle()">Toggle recording</button>
- 将“recording_toggle”函数调用发送到 SWF 本身。