在网页中,javascript & as3 设置如下:
ExternalInterface.call("javascriptFunctionName", "");
javascriptFunctionName()
使用由 ExternalInterface.addCallback 设置的 actionscript 函数 目前,
javascriptFunctionName()
首先检查它是否可以访问 ActionScript 的回调函数。这个检查有必要吗?或者, ActionScript 设法调用 javascript 函数这一事实是否表明已授予访问权限?
编辑:更具体地说,我的代码有效。我担心它可能会放在具有不同权限的第三方页面中。
最佳答案
JavaScript/Flash 通信有几种不同的场景,具有不同的安全要求。
JavaScript 可以与 Flash 通信。
如果参数
allowScriptAccess
设置为 "sameDomain"
(默认)或 "always"
,Flash 可以与 JavaScript 通信。例如 http://example.com/a.swf 加载到 http://example.com/a.html
如果从 Flash 调用
Security.allowDomain(exactDomain)
或 Security.allowDomain('*')
,JavaScript 可以与 Flash 通信。如果参数
allowScriptAccess
设置为 "always"
,Flash 可以与 JavaScript 通信例如 http://swf.example.com/a.swf 加载到 http://example.com/a.html
如果从 Flash 调用
Security.allowInsecureDomain(exactDomain)
或 Security.allowInsecureDomain('*')
,JavaScript 可以与 Flash 通信。如果参数
allowScriptAccess
设置为 "always"
,Flash 可以与 JavaScript 通信例如 https://example.com/a.swf 加载到 http://example.com/a.html
要回答您是否有必要检查通信是否正常的问题,如果您想立即显示错误消息,答案可能是肯定的。无论哪种方式,我都会在双方的每个调用周围使用
try..catch
。关于javascript - ExternalInterface.call 有效,但 javascript 无法访问 actionscript 回调?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18298049/