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

Nic*_*ick 5 flash actionscript-3 externalinterface

我有一个小测试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()
Run Code Online (Sandbox Code Playgroud)

这是ActionScript:

 import flash.external.ExternalInterface

function callMe(name:String):String{

    return "busy signal";

    }

    ExternalInterface.addCallback("myFunction",callMe);
Run Code Online (Sandbox Code Playgroud)

和JS:

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

</script>
Run Code Online (Sandbox Code Playgroud)

最后HTML对象:

<object width="550" height="400">
<param name="movie" value="externalinterface.swf">
<embed src="externalinterface.swf" width="550" height="400">
</embed>
</object>
Run Code Online (Sandbox Code Playgroud)

我们如何解决这个问题?

Raf*_*afH 6

如果你测试在线或localhost,它应该工作,如果你有param allowscriptaccess ="true"像圆顶说.如果您使用file:// protocol进行测试,则需要在闪存播放器安全选项中允许您的驱动器.

  • 对于其他任何人,您的全局安全设置都在http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html进行了编辑. (4认同)