Is there a way to call a Javascript class method f

2019-05-20 03:57发布

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?

2条回答
叼着烟拽天下
2楼-- · 2019-05-20 04:33

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.

查看更多
甜甜的少女心
3楼-- · 2019-05-20 04:44

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.

查看更多
登录 后发表回答