我有一个小测试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错误:
( 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>
我们如何解决这个问题?
解决方法
如果你测试在线或localhost,它应该工作,如果你有param allowscriptaccess =“true”像圆顶说. 如果您使用file:// protocol进行测试,则需要在闪存播放器安全选项中允许您的驱动器.