有没有办法从ExternalInterface调用Javascript类方法?

发布于 2024-10-06 15:20:06 字数 229 浏览 0 评论 0原文

我可以使用 ExternalInterface.call('func_name',.args) 调用 JS 函数。好的,

但是如果我想调用 js 类实例方法怎么办?

ExternalInterface.call('obj.method_name',.args) //this seems not to work

有什么办法可以做到吗?

I can call JS functions with ExternalInterface.call('func_name',.args). OK

But what if I would like to call a js class instance method instead?

ExternalInterface.call('obj.method_name',.args) //this seems not to work

Is there any way of doing it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灯下孤影 2024-10-13 15:20:07

这只是范围问题。您必须在 js 类之外实例化 swf 对象。然后我可以在 ExternalInterface.call() 中引用它。

window.addEvent('domready',function(){

    swf = new Swiff('../files/swf/italy.swf',{
        id:'italy',
        container:'italy-flash',
        width:280,
        height:323,
        params:{
            bgcolor:'#ffffff',
            wmode:'opaque',
            allowScriptAccess:'always'
        }
    });

    rm = new RelessersManager('regions');

});

现在我可以从 swf 调用 rm 方法。 :) (.call('rm.method_name',...params))
以前,我在 rm 中构建了 swf,因此无法从 swf 引用 rm

It was only a matter of scope. You must instantiated the swf object outside the js class. Then I can reference it in ExternalInterface.call().

window.addEvent('domready',function(){

    swf = new Swiff('../files/swf/italy.swf',{
        id:'italy',
        container:'italy-flash',
        width:280,
        height:323,
        params:{
            bgcolor:'#ffffff',
            wmode:'opaque',
            allowScriptAccess:'always'
        }
    });

    rm = new RelessersManager('regions');

});

Now from the swf I can call the rm methods. :) (.call('rm.method_name',...params))
Previously, I built the swf inside rm, so there was no way to reference rm from the swf.

风筝有风,海豚有海 2024-10-13 15:20:07

您可以使用ExternalInterface 调用JavaScript 方法。
确保您已包含 JavaScript 文件或已在 index.template.html 文件中编写 JavaScript 函数,这可能如下所示:

<script type="text/javascript" src="./lib/file.js"></script>
<script type="text/javascript">   
  function doSomtething() {
    alert("Something is done");
  }
</script>

如果您想调用函数“doSomething()”,您可以使用以下命令执行此操作以下代码:

ExternalInterface.call("doSomething");

如果您想发送一些参数,并且您的 JavaScript 函数定义如下:

<script type="text/javascript">   
  function doSomtething(param1, param2) {
    alert("Something is done");
  }
</script>

您可以使用以下语句调用它:

ExternalInterface.call("doSomething", param1, param2);

如果这不起作用,请检查 html 文件中的 JavaScript 函数。

您发布了以下声明:

ExternalInterface.call('obj.method_name',.args)

您确定要发送“.args”而不是“args”吗?

我希望这会对您有所帮助。

You can call a JavaScript-Method with ExternalInterface.
Be sure, you have included your JavaScript-Files or you have written your JavaScript-Function inside your index.template.html-file, this could looks like:

<script type="text/javascript" src="./lib/file.js"></script>
<script type="text/javascript">   
  function doSomtething() {
    alert("Something is done");
  }
</script>

If you want to call the function "doSomething()" you can do this with the following code:

ExternalInterface.call("doSomething");

If you want to send some parameter and your JavaScript Function is defined like this:

<script type="text/javascript">   
  function doSomtething(param1, param2) {
    alert("Something is done");
  }
</script>

You can call it with this statement:

ExternalInterface.call("doSomething", param1, param2);

If this is not working, check your JavaScript-Functions inside your html-file.

You have posted the following statement:

ExternalInterface.call('obj.method_name',.args)

Are you sure you want to send ".args" instead of "args"?

I hope this will help you a little bit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文