我有一个小测试 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()
这是动作脚本:
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>
我们如何解决这个问题?