可以使用`ExternalInterface.call()`函数为swf文件初始化javascript吗?

时间:2016-03-03 17:28:47

标签: javascript actionscript-3

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

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() sunction中的第二个参数传递?

类似

in 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桥是否开启?

1 个答案:

答案 0 :(得分:0)

您可以传递objectID

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

JS:

var SoundsObj = null;

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

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