开发者

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

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.me开发者_Go百科thod_name',.args) //this seems not to work

Is there any way of doing it?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜