尝试从 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 错误:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你在线或本地测试,如果你有像 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.