函数时出现安全错误

函数时出现安全错误

本文介绍了尝试从 JS 调用 ActionScript 函数时出现安全错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小测试 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 错误:

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()

这是动作脚本:

 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 对象:

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?

推荐答案

如果你在线或本地测试,如果你有参数 allowscriptaccess="true" 就像 dome 说的那样,它应该可以工作.如果您使用 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.

这篇关于尝试从 JS 调用 ActionScript 函数时出现安全错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 01:59