Flash CS3 文档 |
|||
| ActionScript 3.0 编程 > Flash Player 安全性 > 限制网络 API | |||
可以控制 SWF 文件对网络功能的访问,方法是通过在包含 SWF 内容的 HTML 页面的 <object> 和 <embed> 标签中设置 allowNetworking 参数。
allowNetworking 的可能值包括:
“all”(默认值)― SWF 文件中允许使用所有网络 API。“internal”― SWF 文件可能不调用浏览器导航或浏览器交互 API(在本节后面部分中列出),但是它会调用任何其它网络 API。“none”― SWF 文件可能不调用浏览器导航或浏览器交互 API(在本节后面部分中列出),并且它无法使用任何 SWF 到 SWF 通信 API(也在本节后面部分中列出)。调用被禁止的 API 会引发 SecurityError 异常。
要设置 allowNetworking 参数,在包含 SWF 文件引用的 HTML 页面的 <object> 和 <embed> 标签中添加 allowNetworking 参数并设置参数值,如下面的示例中所示:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,18,0" width="600" height="400" id="test" align="middle"><param name="allowNetworking" value="none" /><param name="movie" value="test.swf" /> <param name="bgcolor" value="#333333" /> <embed src="test.swf"allowNetworking="none"bgcolor="#333333" width="600" height="400" name="test" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer_cn" /> </object>
HTML 页面也可能会使用脚本来生成 SWF 嵌入式标签。您需要更改该脚本,以便让它能够插入适当的 allowNetworking 设置。由 Flash 和 Adobe Flex Builder 生成的 HTML 页面使用 AC_FL_RunContent() 函数嵌入 SWF 文件的引用,您需要将 allowNetworking 参数设置添加到该脚本,如下所示:
AC_FL_RunContent( ... "allowNetworking", "none", ...)
当 allowNetworking 设置为 "internal" 时,以下 API 被禁止:
navigateToURL() fscommand() ExternalInterface.call() 当 allowNetworking 设置为 "none" 时,除了上面列出的那些 API 外,还会禁止以下 API:
sendToURL() FileReference.download() FileReference.upload() Loader.load() LocalConnection.connect() LocalConnection.send() NetConnection.connect() NetStream.play() Security.loadPolicyFile() SharedObject.getLocal() SharedObject.getRemote() Socket.connect() Sound.load() URLLoader.load() URLStream.load() XMLSocket.connect() 即使所选 allowNetworking 设置允许 SWF 文件使用网络 API,但根据安全沙箱的限制,还可能存在其它限制(如本章所述)。
当 allowNetworking 设置为“none”时,无法在 TextField 对象 htmlText 属性的 <img> 标签中引用外部媒体(这会引发 SecurityError 异常)。
当 allowNetworking 设置为 "none" 时,从导入的共享库添加到 Flash 创作工具(而不是 ActionScript)中的元件在运行时被阻止。
Flash CS3
当前页: http://livedocs.adobe.com/flash/9.0_cn/main/00000351.html