swf 文件可以使用 'ExternalInterface.call()' 函数为 javascript 初始化自身

can swf file initialize itself for javascript with `ExternalInterface.call()` function?

本文关键字:函数 javascript 初始化 call 可以使 文件 ExternalInterface swf      更新时间:2023-09-26

在我的代码中有初始化函数

.html

<embed id="SoundsObj"........

.js

var SoundsObj = document.getElementById('SoundsObj');
function GetSoundsObj(){
alert(top.SoundsObj.SndPlay); //I can see it has initialized itself
}

AS3

ExternalInterface.call("GetSoundsObj");

我很好奇我是否有可能在 JS 中传递 swf 对象作为 ExternalInterface.call() 中的第二个参数?

类似的东西

在 AS3 中

    ExternalInterface.call("GetSoundsObj",this); //by `this` I mean swf object

在 js 中

var SoundsObj = null;
function GetSoundsObj(arg){
SoundsObj = arg;
alert(SoundsObj.SndPlay);
}

要完全确定 SWF-JS 网桥已打开?

你可以通过objectID

ExternalInterface.call("GetSoundsObj", ExternalInterface.objectID);

.JS:

var SoundsObj = null;
function GetSoundsObj(swfId){
    SoundsObj = document.getElementById(swfId);
    alert(SoundsObj.SndPlay);
}

请注意,您应该在<embed>标签和id上设置 name 属性,或者只使用 <object> 标签。