Is there a way to call a Javascript class method from ExternalInterface?

点点圈 提交于 2019-12-06 07:35:40
Luca

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!