尝试从 JS 调用 ActionScript 函数时出现安全错误

发布于 2024-08-22 13:06:57 字数 1452 浏览 3 评论 0原文

我有一个小测试 swf 来测试从 JavaScript 调用 ActionScript(3.0) 函数。我使用 Flash 文档作为参考: (http://www.adobe.ca/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000340.html) 当页面加载时,我会看到 Flash Player 错误:

SecurityError: Error #2060: Security sandbox violation: ExternalInterface caller file: c:/externalinterface.swf cannot access file: c:\myhtml.html
at flash.external::ExternalInterface$/_initJS()
    at flash.external::ExternalInterface$/addCallback()
    at externalinterface_fla::MainTimeline/frame1()

这是 ActionScript:

 import flash.external.ExternalInterface

function callMe(name:String):String{

    return "busy signal";

    }

    ExternalInterface.addCallback("myFunction",callMe);

和 JS:

<script type="text/javascript" language="javascript">
    function callSwf() {
        var callResult = flashObject.myFunction("Nick");
        alert(callResult);
    }   

</script>

最后是 HTML 对象:

<object width="550" height="400">
<param name="movie" value="externalinterface.swf">
<embed src="externalinterface.swf" width="550" height="400">
</embed>
</object>

我们如何解决这个问题?

I have a little test swf to test calling an ActionScript(3.0) function from JavaScript. I am using the Flash documentation as a reference:
(http://www.adobe.ca/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000340.html)
When the page loads I am presented with a Flash Player error:

SecurityError: Error #2060: Security sandbox violation: ExternalInterface caller file: c:/externalinterface.swf cannot access file: c:\myhtml.html
at flash.external::ExternalInterface$/_initJS()
    at flash.external::ExternalInterface$/addCallback()
    at externalinterface_fla::MainTimeline/frame1()

This is the ActionScript:

 import flash.external.ExternalInterface

function callMe(name:String):String{

    return "busy signal";

    }

    ExternalInterface.addCallback("myFunction",callMe);

And the JS:

<script type="text/javascript" language="javascript">
    function callSwf() {
        var callResult = flashObject.myFunction("Nick");
        alert(callResult);
    }   

</script>

Finally the HTML Object:

<object width="550" height="400">
<param name="movie" value="externalinterface.swf">
<embed src="externalinterface.swf" width="550" height="400">
</embed>
</object>

How do we work around this?

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

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

发布评论

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

评论(1

坏尐絯 2024-08-29 13:06:58

如果你在线或本地测试,如果你有像 dome 所说的参数allowscriptaccess =“true”,它应该可以工作。
如果您使用 file:// 协议进行测试,则需要在 Flash Player 安全选项中允许您的驱动器。

if you test online or localhost, it should work if you had the param allowscriptaccess="true" like dome said.
If you are testing with file:// protocol you need to allow your drive in the flash player security options.

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