有没有办法从ExternalInterface调用Javascript类方法?
我可以使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这只是范围问题。您必须在 js 类之外实例化 swf 对象。然后我可以在
ExternalInterface.call()
中引用它。现在我可以从 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()
.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 referencerm
from the swf.您可以使用ExternalInterface 调用JavaScript 方法。
确保您已包含 JavaScript 文件或已在 index.template.html 文件中编写 JavaScript 函数,这可能如下所示:
如果您想调用函数“doSomething()”,您可以使用以下命令执行此操作以下代码:
如果您想发送一些参数,并且您的 JavaScript 函数定义如下:
您可以使用以下语句调用它:
如果这不起作用,请检查 html 文件中的 JavaScript 函数。
您发布了以下声明:
您确定要发送“.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:
If you want to call the function "doSomething()" you can do this with the following code:
If you want to send some parameter and your JavaScript Function is defined like this:
You can call it with this statement:
If this is not working, check your JavaScript-Functions inside your html-file.
You have posted the following statement:
Are you sure you want to send ".args" instead of "args"?
I hope this will help you a little bit.