<?xml version="1.0" encoding="UTF-8"?>
<apiPackage xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" id="flash.external" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiPackage/apiPackage "><apiName class="- topic/title reference/title apiRef/apiName ">flash.external</apiName><apiDetail class="- topic/body reference/refbody apiRef/apiDetail "/><apiClassifier languages="" id="flash.external:ExtensionContext" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiClassifier/apiClassifier "><apiName class="- topic/title reference/title apiRef/apiName ">ExtensionContext</apiName><shortdesc class="- topic/shortdesc ">
         ExtensionContext 类为在 ActionScript 扩展的本机实现中调用函数提供接口。</shortdesc><prolog class="- topic/prolog "><asMetadata class="+ topic/metadata adobe-api-d/asMetadata "><apiVersion class="+ topic/ph adobe-api-d/apiVersion "><apiLanguage version="3.0" class="+ topic/ph adobe-api-d/apiLanguage "/><apiPlatform description="" name="AIR" version="2.5" class="+ topic/ph adobe-api-d/apiPlatform "/></apiVersion></asMetadata></prolog><apiClassifierDetail class="- topic/body reference/refbody apiRef/apiDetail apiClassifier/apiClassifierDetail "><apiClassifierDef class="- topic/section reference/section apiRef/apiDef apiClassifier/apiClassifierDef "><apiAccess value="public" class="- topic/state reference/state apiRef/apiQualifier adobe-api-d/apiAccess "/><apiStatic class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiStatic "/><apiFinal class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiFinal "/><apiBaseClassifier class="- topic/xref reference/xref apiRef/apiRelation apiClassifier/apiBaseClassifier ">flash.events:EventDispatcher</apiBaseClassifier></apiClassifierDef><apiDesc class="- topic/section reference/section apiRef/apiDesc ">
         ExtensionContext 类为在 ActionScript 扩展的本机实现中调用函数提供接口。此类只能在作为扩展的一部分的 ActionScript 类中使用。
		 
		 <p class="- topic/p "><i class="+ topic/ph hi-d/i ">AIR 配置文件支持：</i>在使用 <codeph class="+ topic/ph pr-d/codeph ">extendedTV</codeph> 设备配置文件的应用程序中，仅用于电视的 AIR 设备支持此功能。</p>
	 	 
         <p class="- topic/p ">ActionScript 扩展是以下内容的组合：</p>
         
         <p class="- topic/p "><ul class="- topic/ul "><li class="- topic/li ">ActionScript 类.</li><li class="- topic/li ">本机代码。本机代码是在没有运行时的设备上执行的代码。例如，C 语言编写的代码就是本机代码。</li></ul></p>
         
         <p class="- topic/p ">您可以创建 ActionScript 扩展，使 AIR 应用程序可以访问设备特定的功能。创建 ActionScript 扩展的其他原因是，重复使用现有的本机代码，或者使用本机代码可以比使用 ActionScript 代码提供更高的处理效率。有关编写、构建和打包 ActionScript 扩展的详细信息，请参阅 PDF <xref href="http://www.adobe.com/go/learn_air_as_extensions_en" class="- topic/xref "> 针对 Adobe AIR 开发 ActionScript 扩展</xref>。
         </p>
         
         <p class="- topic/p ">在 ActionScript 扩展的 ActionScript 端使用 ExtensionContext 类，以访问扩展的本机端。首先，创建 ExtensionContext 类的实例。为此，请调用静态方法 <codeph class="+ topic/ph pr-d/codeph ">ExtensionContext.createExtensionContext()</codeph>。</p>
		 
		 <p class="- topic/p ">创建 ExtensionContext 实例后，使用该实例的 <codeph class="+ topic/ph pr-d/codeph ">call()</codeph> 方法调用本机函数。</p>
		 
		 <p class="- topic/p ">对 ExtensionContext 实例完成操作后，调用 <codeph class="+ topic/ph pr-d/codeph ">dispose()</codeph> 以释放任何关联的本机资源。运行时垃圾回收器在处理此实例时调用 <codeph class="+ topic/ph pr-d/codeph ">dispose()</codeph>，而不显式调用 <codeph class="+ topic/ph pr-d/codeph ">dispose()</codeph>。显式调用 <codeph class="+ topic/ph pr-d/codeph ">dispose()</codeph> 通常比等待垃圾回收器执行操作的时间要早得多。</p>
         
         <p class="- topic/p ">ExtensionContext 实例可侦听当扩展的本机实现中发生某些异步事件时由本机代码调度的 StatusEvent 事件。由于 ExtensionContext 类派生自 EventDispatcher，因此它可以依次调度事件。</p>
		  
		 <p class="- topic/p ">ExtensionContext 类还提供了一个静态方法 <codeph class="+ topic/ph pr-d/codeph ">getExtensionDirectory()</codeph>，用于访问扩展在设备上的安装目录。它还提供了一个 <codeph class="+ topic/ph pr-d/codeph ">actionScriptData</codeph> 属性，用于与扩展的本机实现共享数据。</p>
		 
		 <p class="- topic/p "><b class="+ topic/ph hi-d/b ">注意：</b>使用 <codeph class="+ topic/ph pr-d/codeph ">extendedDesktop</codeph> 配置文件的 AIR 应用程序可使用 NativeProcess 类来执行本机进程。</p>  
		 
         </apiDesc></apiClassifierDetail><related-links class="- topic/related-links "><link href="http://www.adobe.com/go/learn_air_as_extensions_en" class="- topic/link "><linktext class="- topic/linktext ">针对 Adobe AIR 开发 ActionScript 扩展</linktext></link><link href="flash.desktop.xml#NativeProcess" class="- topic/link "><linktext class="- topic/linktext ">flash.desktop.NativeProcess</linktext></link></related-links><apiOperation id="flash.external:ExtensionContext:call" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiOperation/apiOperation "><apiName class="- topic/title reference/title apiRef/apiName ">call</apiName><shortdesc class="- topic/shortdesc ">
             调用由 functionName 指定的本机函数。</shortdesc><prolog class="- topic/prolog "><asMetadata class="+ topic/metadata adobe-api-d/asMetadata "><apiVersion class="+ topic/ph adobe-api-d/apiVersion "><apiLanguage version="3.0" class="+ topic/ph adobe-api-d/apiLanguage "/><apiPlatform description="" name="AIR" version="2.5" class="+ topic/ph adobe-api-d/apiPlatform "/></apiVersion></asMetadata></prolog><apiOperationDetail class="- topic/body reference/refbody apiRef/apiDetail apiOperation/apiOperationDetail "><apiOperationDef class="- topic/section reference/section apiRef/apiDef apiOperation/apiOperationDef "><apiAccess value="public" class="- topic/state reference/state apiRef/apiQualifier adobe-api-d/apiAccess "/><apiException class="+ topic/ph reference/ph apiRef/apiDefItem apiOperation/apiEvent adobe-api-d/apiException "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">不存在与 <codeph class="+ topic/ph pr-d/codeph ">functionName</codeph> 给定的名称对应的函数。
             
             </apiDesc><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">ArgumentError</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">ArgumentError</apiOperationClassifier></apiException><apiException class="+ topic/ph reference/ph apiRef/apiDefItem apiOperation/apiEvent adobe-api-d/apiException "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">已对此 ExtensionContext 实例调用 <codeph class="+ topic/ph pr-d/codeph ">dispose()</codeph> 方法。如果本机函数返回无效的对象引用，也会引发此错误。
             
		 	 </apiDesc><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">IllegalOperationError</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">flash.errors:IllegalOperationError</apiOperationClassifier></apiException><apiReturn class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiReturn "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">由本机函数返回的值。如果本机函数未返回值或返回无效的对象引用，则返回值为 <codeph class="+ topic/ph pr-d/codeph ">null</codeph>。
             
             </apiDesc><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">Object</apiOperationClassifier></apiReturn><apiParam class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiParam "><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">functionName</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">String</apiOperationClassifier><apiDesc class="- topic/section reference/section apiRef/apiDesc ">表示本机实现中的函数的名称。此名称不一定是本机函数的实际名称，它可以是在扩展的 ActionScript 端和本机端之间约定的任何名称。
			 
			 </apiDesc></apiParam><apiParam class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiParam "><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">args</apiItemName><apiType value="restParam" name="type" class="- topic/state reference/state apiRef/apiType "/><apiDesc class="- topic/section reference/section apiRef/apiDesc ">本机函数的参数列表。这些参数可以是任何原始类型的 ActionScript 对象或 ActionScript 类对象。参数的类型和顺序在扩展的 ActionScript 端和本机端之间约定。
			 
			 </apiDesc></apiParam></apiOperationDef><apiDesc class="- topic/section reference/section apiRef/apiDesc ">
             调用由 <codeph class="+ topic/ph pr-d/codeph ">functionName</codeph> 指定的本机函数。任何其他参数都将传递到本机函数。
             
             </apiDesc></apiOperationDetail></apiOperation><apiOperation id="flash.external:ExtensionContext:createExtensionContext" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiOperation/apiOperation "><apiName class="- topic/title reference/title apiRef/apiName ">createExtensionContext</apiName><shortdesc class="- topic/shortdesc ">
             为给定的扩展标识符和上下文类型创建 ExtensionContext 实例。</shortdesc><prolog class="- topic/prolog "><asMetadata class="+ topic/metadata adobe-api-d/asMetadata "><apiVersion class="+ topic/ph adobe-api-d/apiVersion "><apiLanguage version="3.0" class="+ topic/ph adobe-api-d/apiLanguage "/><apiPlatform description="" name="AIR" version="2.5" class="+ topic/ph adobe-api-d/apiPlatform "/></apiVersion></asMetadata></prolog><apiOperationDetail class="- topic/body reference/refbody apiRef/apiDetail apiOperation/apiOperationDetail "><apiOperationDef class="- topic/section reference/section apiRef/apiDef apiOperation/apiOperationDef "><apiAccess value="public" class="- topic/state reference/state apiRef/apiQualifier adobe-api-d/apiAccess "/><apiStatic class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiStatic "/><apiException class="+ topic/ph reference/ph apiRef/apiDefItem apiOperation/apiEvent adobe-api-d/apiException "><apiDesc class="- topic/section reference/section apiRef/apiDesc "><codeph class="+ topic/ph pr-d/codeph ">extensionID</codeph> 参数为 <codeph class="+ topic/ph pr-d/codeph ">null</codeph> 或者非有效扩展 ID。
			 
		 	 </apiDesc><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">ArgumentError</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">ArgumentError</apiOperationClassifier></apiException><apiReturn class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiReturn "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">新 ExtensionContext 实例。如果不存在具有给定的 <codeph class="+ topic/ph pr-d/codeph ">extensionID</codeph> 值的扩展，则返回 <codeph class="+ topic/ph pr-d/codeph ">null</codeph>。
             
             </apiDesc><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">flash.external:ExtensionContext</apiOperationClassifier></apiReturn><apiParam class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiParam "><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">extensionID</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">String</apiOperationClassifier><apiDesc class="- topic/section reference/section apiRef/apiDesc ">扩展的扩展标识符。此标识符的值与扩展描述符文件中的 <codeph class="+ topic/ph pr-d/codeph ">id</codeph> 元素的值相同。应用程序开发人员还将此值用于应用程序描述符文件中的 <codeph class="+ topic/ph pr-d/codeph ">extensionID</codeph> 元素。所有扩展共享一个全局命名空间。因此，为避免名称冲突，请对扩展标识符使用反向 DNS 表示法。
			 
             </apiDesc></apiParam><apiParam class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiParam "><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">contextType</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">String</apiOperationClassifier><apiDesc class="- topic/section reference/section apiRef/apiDesc ">扩展的上下文类型。根据上下文类型，本机实现可执行不同的初始化操作。这些不同的操作可以包括本机实现指定 ActionScript 端可调用的另外不同的一组可用本机函数。上下文类型的值是扩展的 ActionScript 端和本机端之间约定的任意字符串。不同的上下文类型通常不需要简单扩展。在这些情况下，将为 <codeph class="+ topic/ph pr-d/codeph ">contextType</codeph> 值传递空字符串 <codeph class="+ topic/ph pr-d/codeph ">""</codeph> 或 <codeph class="+ topic/ph pr-d/codeph ">null</codeph>。
			 
			 </apiDesc></apiParam></apiOperationDef><apiDesc class="- topic/section reference/section apiRef/apiDesc ">
             为给定的扩展标识符和上下文类型创建 ExtensionContext 实例。
             
			 </apiDesc></apiOperationDetail></apiOperation><apiOperation id="flash.external:ExtensionContext:dispose" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiOperation/apiOperation "><apiName class="- topic/title reference/title apiRef/apiName ">dispose</apiName><shortdesc class="- topic/shortdesc ">
             此 ExtensionContext 实例的处理。</shortdesc><prolog class="- topic/prolog "><asMetadata class="+ topic/metadata adobe-api-d/asMetadata "><apiVersion class="+ topic/ph adobe-api-d/apiVersion "><apiLanguage version="3.0" class="+ topic/ph adobe-api-d/apiLanguage "/><apiPlatform description="" name="AIR" version="2.5" class="+ topic/ph adobe-api-d/apiPlatform "/></apiVersion></asMetadata></prolog><apiOperationDetail class="- topic/body reference/refbody apiRef/apiDetail apiOperation/apiOperationDetail "><apiOperationDef class="- topic/section reference/section apiRef/apiDef apiOperation/apiOperationDef "><apiAccess value="public" class="- topic/state reference/state apiRef/apiQualifier adobe-api-d/apiAccess "/><apiReturn class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiReturn "><apiType value="void" name="type" class="- topic/state reference/state apiRef/apiType "/></apiReturn></apiOperationDef><apiDesc class="- topic/section reference/section apiRef/apiDesc ">
             此 ExtensionContext 实例的处理。 
			 
			 <p class="- topic/p ">运行时通知本机实现，这可以释放任何关联的本机资源。调用 <codeph class="+ topic/ph pr-d/codeph ">dispose()</codeph> 后，代码无法调用 <codeph class="+ topic/ph pr-d/codeph ">call()</codeph> 方法且无法获取或设置 <codeph class="+ topic/ph pr-d/codeph ">actionScriptData</codeph> 属性。</p>
			 
		 	 </apiDesc></apiOperationDetail></apiOperation><apiOperation id="flash.external:ExtensionContext:getExtensionDirectory" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiOperation/apiOperation "><apiName class="- topic/title reference/title apiRef/apiName ">getExtensionDirectory</apiName><shortdesc class="- topic/shortdesc ">
			 返回设备上安装扩展的目录。</shortdesc><prolog class="- topic/prolog "><asMetadata class="+ topic/metadata adobe-api-d/asMetadata "><apiVersion class="+ topic/ph adobe-api-d/apiVersion "><apiLanguage version="3.0" class="+ topic/ph adobe-api-d/apiLanguage "/><apiPlatform description="" name="AIR" version="2.5" class="+ topic/ph adobe-api-d/apiPlatform "/></apiVersion></asMetadata></prolog><apiOperationDetail class="- topic/body reference/refbody apiRef/apiDetail apiOperation/apiOperationDetail "><apiOperationDef class="- topic/section reference/section apiRef/apiDef apiOperation/apiOperationDef "><apiAccess value="public" class="- topic/state reference/state apiRef/apiQualifier adobe-api-d/apiAccess "/><apiStatic class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiStatic "/><apiException class="+ topic/ph reference/ph apiRef/apiDefItem apiOperation/apiEvent adobe-api-d/apiException "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">目录不存在。原因很可能是指定的 <codeph class="+ topic/ph pr-d/codeph ">extensionID</codeph> 无效。
			 
			 </apiDesc><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">IOError</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">flash.errors:IOError</apiOperationClassifier></apiException><apiReturn class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiReturn "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">安装扩展的目录的 File 实例。
			 
			 </apiDesc><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">flash.filesystem:File</apiOperationClassifier></apiReturn><apiParam class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiParam "><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">extensionID</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">String</apiOperationClassifier><apiDesc class="- topic/section reference/section apiRef/apiDesc ">扩展的扩展标识符。此标识符的值与 <codeph class="+ topic/ph pr-d/codeph ">createExtensionContext()</codeph> 中的 <codeph class="+ topic/ph pr-d/codeph ">extensionID</codeph> 参数的值相同。 
			 
			 </apiDesc></apiParam></apiOperationDef><apiDesc class="- topic/section reference/section apiRef/apiDesc ">
			 返回设备上安装扩展的目录。
			 
			 <p class="- topic/p ">有时，扩展包括要从该扩展的 ActionScript 代码访问的资源，例如图像。有时，代码也需要扩展描述符文件中提供的信息，例如扩展版本号。可以使用此方法访问扩展的基本目录。</p>
			 
			 <p class="- topic/p ">不管扩展位于设备中的任何位置，该扩展的文件与该扩展的基本目录的相对位置始终不变。使用由此方法返回的 File 实例，可以导航到扩展附带的特定文件并进行操作。</p>
			 
			 </apiDesc></apiOperationDetail></apiOperation><apiValue id="flash.external:ExtensionContext:actionScriptData:get" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiValue/apiValue "><apiName class="- topic/title reference/title apiRef/apiName ">actionScriptData</apiName><shortdesc class="- topic/shortdesc "> 
             与此上下文关联的 ActionScript 对象（如果有）。</shortdesc><prolog class="- topic/prolog "><asMetadata class="+ topic/metadata adobe-api-d/asMetadata "><apiVersion class="+ topic/ph adobe-api-d/apiVersion "><apiLanguage version="3.0" class="+ topic/ph adobe-api-d/apiLanguage "/><apiPlatform description="" name="AIR" version="2.5" class="+ topic/ph adobe-api-d/apiPlatform "/></apiVersion></asMetadata></prolog><apiValueDetail class="- topic/body reference/refbody apiRef/apiDetail apiValue/apiValueDetail "><apiValueDef class="- topic/section reference/section apiRef/apiDef apiValue/apiValueDef "><apiProperty class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiProperty "/><apiAccess value="public" class="- topic/state reference/state apiRef/apiQualifier adobe-api-d/apiAccess "/><apiDynamic class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiDynamic "/><apiValueAccess value="readwrite" class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiValueAccess "/><apiValueClassifier class="- topic/xref reference/xref apiRef/apiRelation apiValue/apiValueClassifier ">Object</apiValueClassifier><apiException class="+ topic/ph reference/ph apiRef/apiDefItem apiOperation/apiEvent adobe-api-d/apiException "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">已对此 ExtensionContext 实例调用方法 <codeph class="+ topic/ph pr-d/codeph ">dispose()</codeph>。
             
		 	 </apiDesc><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">IllegalOperationError</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">flash.errors:IllegalOperationError</apiOperationClassifier></apiException></apiValueDef><apiDesc class="- topic/section reference/section apiRef/apiDesc "> 
             与此上下文关联的 ActionScript 对象（如果有）。
			 
			 <p class="- topic/p ">可以将任何 ActionScript 对象与 ExtensionContext 实例关联。本机实现也可以获取和设置此 ActionScript 对象。因此，可以使用 <codeph class="+ topic/ph pr-d/codeph ">actionScriptData</codeph> 在扩展的 ActionScript 端和本机端之间共享数据。</p>
			 
			 <p class="- topic/p ">还可以将 <codeph class="+ topic/ph pr-d/codeph ">actionScriptData</codeph> 的值设置为 <codeph class="+ topic/ph pr-d/codeph ">null</codeph>。</p>
 			 
             
             </apiDesc></apiValueDetail></apiValue></apiClassifier><apiClassifier languages="" id="flash.external:ExternalInterface" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiClassifier/apiClassifier "><apiName class="- topic/title reference/title apiRef/apiName ">ExternalInterface</apiName><shortdesc class="- topic/shortdesc ">
 ExternalInterface 类是用来支持在 ActionScript 和 SWF 容器（例如，含有 JavaScript 的 HTML 页或使用 Flash Player 播放 SWF 文件的桌面应用程序）之间进行直接通信的应用程序编程接口。</shortdesc><prolog class="- topic/prolog "><asMetadata class="+ topic/metadata adobe-api-d/asMetadata "><apiVersion class="+ topic/ph adobe-api-d/apiVersion "><apiLanguage version="3.0" class="+ topic/ph adobe-api-d/apiLanguage "/><apiPlatform description="" name="Flash" version="9" class="+ topic/ph adobe-api-d/apiPlatform "/><apiPlatform description="" name="Lite" version="4" class="+ topic/ph adobe-api-d/apiPlatform "/></apiVersion></asMetadata><asCustoms class="+ topic/metadata adobe-api-d/asCustoms "><internal>Verify table is still correct and paragraph below the table still applies.
 </internal></asCustoms></prolog><apiClassifierDetail class="- topic/body reference/refbody apiRef/apiDetail apiClassifier/apiClassifierDetail "><apiClassifierDef class="- topic/section reference/section apiRef/apiDef apiClassifier/apiClassifierDef "><apiAccess value="public" class="- topic/state reference/state apiRef/apiQualifier adobe-api-d/apiAccess "/><apiStatic class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiStatic "/><apiFinal class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiFinal "/><apiTipTexts><apiTipText class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiTipText ">实现 ActionScript 与容器之间的通信。
 
 </apiTipText></apiTipTexts><apiBaseClassifier class="- topic/xref reference/xref apiRef/apiRelation apiClassifier/apiBaseClassifier ">Object</apiBaseClassifier></apiClassifierDef><apiDesc class="- topic/section reference/section apiRef/apiDesc ">
 ExternalInterface 类是用来支持在 ActionScript 和 SWF 容器（例如，含有 JavaScript 的 HTML 页或使用 Flash Player 播放 SWF 文件的桌面应用程序）之间进行直接通信的应用程序编程接口。
 
 
 <p class="- topic/p ">通过 ExternalInterface 类，您可以在 Flash 运行时中使用 HTML 页面中的 JavaScript 调用 ActionScript 函数。ActionScript 函数可以返回一个值，JavaScript 会立即接收它作为该调用的返回值。</p>
 
 <p class="- topic/p ">此功能替代 <codeph class="+ topic/ph pr-d/codeph ">fscommand()</codeph> 方法。</p>
 
 <p class="- topic/p ">在以下浏览器和操作系统的组合中可以使用 ExternalInterface 类：</p>
 <adobetable class="innertable"><tgroup cols="3" class="- topic/tgroup "><thead class="- topic/thead "><row class="- topic/row "><entry class="- topic/entry ">浏览器</entry><entry class="- topic/entry ">操作系统</entry><entry class="- topic/entry ">操作系统</entry></row></thead><tbody class="- topic/tbody "><row class="- topic/row "><entry class="- topic/entry ">Internet Explorer 5.0 及更高版本</entry><entry class="- topic/entry ">Windows</entry><entry class="- topic/entry "> </entry></row><row class="- topic/row "><entry class="- topic/entry ">Netscape 8.0 及更高版本</entry><entry class="- topic/entry ">Windows</entry><entry class="- topic/entry "> MacOS </entry></row><row class="- topic/row "><entry class="- topic/entry ">Mozilla 1.7.5 及更高版本</entry><entry class="- topic/entry ">Windows</entry><entry class="- topic/entry "> MacOS </entry></row><row class="- topic/row "><entry class="- topic/entry ">Firefox 1.0 及更高版本</entry><entry class="- topic/entry ">Windows</entry><entry class="- topic/entry "> MacOS </entry></row><row class="- topic/row "><entry class="- topic/entry ">Safari 1.3 及更高版本</entry><entry class="- topic/entry "> </entry><entry class="- topic/entry "> MacOS </entry></row></tbody></tgroup></adobetable>
 
 <p class="- topic/p ">适用于 Linux 的 Flash Player 9.0.31.0 及更高版本在以下浏览器中支持 ExternalInterface 类：</p>
  <adobetable class="innertable"><tgroup cols="1" class="- topic/tgroup "><thead class="- topic/thead "><row class="- topic/row "><entry class="- topic/entry ">浏览器</entry></row></thead><tbody class="- topic/tbody "><row class="- topic/row "><entry class="- topic/entry ">Mozilla 1.7.x 及更高版本</entry></row><row class="- topic/row "><entry class="- topic/entry ">Firefox 1.5.0.7 及更高版本</entry></row><row class="- topic/row "><entry class="- topic/entry ">SeaMonkey 1.0.5 及更高版本 </entry></row></tbody></tgroup></adobetable>
 <p class="- topic/p ">ExternalInterface 类要求用户的 Web 浏览器支持 ActiveX<sup class="+ topic/ph hi-d/sup ">®</sup> 或由某些浏览器公开的 NPRuntime API 以实现插件脚本处理。即使上面未列出浏览器和操作系统组合，如果它们支持 NPRuntime API，则它们也应该支持 ExternalInterface 类。请访问 <xref href="http://www.mozilla.org/projects/plugins/npruntime.html" scope="external" class="- topic/xref ">http://www.mozilla.org/projects/plugins/npruntime.html</xref>。</p>
 <p class="- topic/p "><b class="+ topic/ph hi-d/b ">注意：</b>在将 SWF 文件嵌入到 HTML 页中时，请确保设置 <codeph class="+ topic/ph pr-d/codeph ">id</codeph> 属性，并且 <codeph class="+ topic/ph pr-d/codeph ">object</codeph> 和 <codeph class="+ topic/ph pr-d/codeph ">embed</codeph> 标签的 <codeph class="+ topic/ph pr-d/codeph ">id</codeph> 和 <codeph class="+ topic/ph pr-d/codeph ">name</codeph> 属性不包含以下字符：</p>
 <pre xml:space="preserve" class="- topic/pre ">
 . - + ~~ / \
 </pre>
 <p class="- topic/p "><b class="+ topic/ph hi-d/b ">关于 Flash Player 应用程序的注意事项：</b>Flash Player 版本 9.0.115.0 和更高版本允许<codeph class="+ topic/ph pr-d/codeph ">。</codeph>在 <codeph class="+ topic/ph pr-d/codeph ">id</codeph> 和 <codeph class="+ topic/ph pr-d/codeph ">name</codeph> 属性中使用 .（句点）字符。</p>
 
 <p class="- topic/p "><b class="+ topic/ph hi-d/b ">关于 Flash Player 应用程序的注意事项：</b>在运行于浏览器中的 Flash Player 10 和更高版本中，以编程方式使用此类打开弹出窗口可能会失败。不同的浏览器（和浏览器配置）可能会随时阻止弹出窗口；不能保证可以显示任何弹出窗口。不过，为了尽可能成功，请仅在作为用户操作的直接结果执行的代码中使用此类打开弹出窗口（例如，在鼠标单击或按键事件的事件处理函数中）。</p>
 
 <p class="- topic/p ">利用 ActionScript，可以在 HTML 页上执行以下操作：
 <ul class="- topic/ul "><li class="- topic/li ">调用任何 JavaScript 函数。</li><li class="- topic/li ">传递任意数量、具有任意名称的参数。</li><li class="- topic/li ">传递各种数据类型（Boolean、Number、String 等等）。</li><li class="- topic/li ">接收来自 JavaScript 函数的返回值。</li></ul>
 </p>
 
 <p class="- topic/p ">通过在 HTML 页上使用 JavaScript，可以：
 <ul class="- topic/ul "><li class="- topic/li ">调用 ActionScript 函数。</li><li class="- topic/li ">使用标准的函数调用表示法传递参数。</li><li class="- topic/li ">将值返回给 JavaScript 函数。</li></ul>
 </p>
 
 <p class="- topic/p "><b class="+ topic/ph hi-d/b ">关于 Flash Player 应用程序的注意事项：</b>当前，Flash Player 不支持在 HTML 表单内嵌入的 SWF 文件。</p>
 
 <p class="- topic/p "><b class="+ topic/ph hi-d/b ">关于 AIR 应用程序的注意事项：</b>在 Adobe AIR 中，ExternalInterface 类可用于在以下二者之间通信：一是在 HTMLLoader 控件中加载的 HTML 页面中的 JavaScript，一是在此 HTML 页面中嵌入的 SWF 内中的 ActionScript。</p>
 
 </apiDesc><example conref="examples\ExternalInterfaceExample.as" class="- topic/example "> 以下示例演示了在 Flash Player 与 HTML 容器之间发送数据的过程。
<codeblock xml:space="preserve" class="+ topic/pre pr-d/codeblock ">

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.external.ExternalInterface;
    import flash.text.TextField;
    import flash.utils.Timer;
    import flash.text.TextFieldType;
    import flash.text.TextFieldAutoSize;

    public class ExternalInterfaceExample extends Sprite {
        private var input:TextField;
        private var output:TextField;
        private var sendBtn:Sprite;

        public function ExternalInterfaceExample() {
            input = new TextField();
            input.type = TextFieldType.INPUT;
            input.background = true;
            input.border = true;
            input.width = 350;
            input.height = 18;
            addChild(input);

            sendBtn = new Sprite();
            sendBtn.mouseEnabled = true;
            sendBtn.x = input.width + 10;
            sendBtn.graphics.beginFill(0xCCCCCC);
            sendBtn.graphics.drawRoundRect(0, 0, 80, 18, 10, 10);
            sendBtn.graphics.endFill();
            sendBtn.addEventListener(MouseEvent.CLICK, clickHandler);
            addChild(sendBtn);

            output = new TextField();
            output.y = 25;
            output.width = 450;
            output.height = 325;
            output.multiline = true;
            output.wordWrap = true;
            output.border = true;
            output.text = "Initializing...\n";
            addChild(output);

            if (ExternalInterface.available) {
                try {
                    output.appendText("Adding callback...\n");
                    ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);
                    if (checkJavaScriptReady()) {
                        output.appendText("JavaScript is ready.\n");
                    } else {
                        output.appendText("JavaScript is not ready, creating timer.\n");
                        var readyTimer:Timer = new Timer(100, 0);
                        readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
                        readyTimer.start();
                    }
                } catch (error:SecurityError) {
                    output.appendText("A SecurityError occurred: " + error.message + "\n");
                } catch (error:Error) {
                    output.appendText("An Error occurred: " + error.message + "\n");
                }
            } else {
                output.appendText("External interface is not available for this container.");
            }
        }
        private function receivedFromJavaScript(value:String):void {
            output.appendText("JavaScript says: " + value + "\n");
        }
        private function checkJavaScriptReady():Boolean {
            var isReady:Boolean = ExternalInterface.call("isReady");
            return isReady;
        }
        private function timerHandler(event:TimerEvent):void {
            output.appendText("Checking JavaScript status...\n");
            var isReady:Boolean = checkJavaScriptReady();
            if (isReady) {
                output.appendText("JavaScript is ready.\n");
                Timer(event.target).stop();
            }
        }
        private function clickHandler(event:MouseEvent):void {
            if (ExternalInterface.available) {
                ExternalInterface.call("sendToJavaScript", input.text);
            }
        }
    }
}


</codeblock> 为了测试前面的 ActionScript 代码，请使用以下 HTML 模板嵌入生成的 SWF 文件：
 <codeblock rev="2.0" xml:space="preserve" class="+ topic/pre pr-d/codeblock ">
 &lt;!-- saved from url=(0014)about:internet -->
 &lt;html lang="en">
 &lt;head>
 &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 &lt;title>ExternalInterfaceExample&lt;/title>
 &lt;script language="JavaScript">
     var jsReady = false;
     function isReady() {
         return jsReady;
     }
     function pageInit() {
         jsReady = true;
         document.forms["form1"].output.value += "\n" + "JavaScript is ready.\n";
     }
     function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }
     function sendToActionScript(value) {
         thisMovie("ExternalInterfaceExample").sendToActionScript(value);
     }
     function sendToJavaScript(value) {
         document.forms["form1"].output.value += "ActionScript says: " + value + "\n";
     }
 &lt;/script>
 &lt;/head>
 &lt;body onload="pageInit();">
 
     &lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
             id="ExternalInterfaceExample" width="500" height="375"
             codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
         &lt;param name="movie" value="ExternalInterfaceExample.swf" />
         &lt;param name="quality" value="high" />
         &lt;param name="bgcolor" value="#869ca7" />
         &lt;param name="allowScriptAccess" value="sameDomain" />
         &lt;embed src="ExternalInterfaceExample.swf" quality="high" bgcolor="#869ca7"
             width="500" height="375" name="ExternalInterfaceExample" align="middle"
             play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
             type="application/x-shockwave-flash"
             pluginspage="http://www.macromedia.com/go/getflashplayer">
         &lt;/embed>
     &lt;/object>
 
     &lt;form name="form1" onsubmit="return false;">
         &lt;input type="text" name="input" value="" />
         &lt;input type="button" value="Send" onclick="sendToActionScript(this.form.input.value);" />&lt;br />
         &lt;textarea cols="60" rows="20" name="output" readonly="true">Initializing...&lt;/textarea>
     &lt;/form>
 
 &lt;/body>
 &lt;/html>
 </codeblock>
</example></apiClassifierDetail><related-links class="- topic/related-links "><link href="../../flash/system/package.html#fscommand()" class="- topic/link "><linktext class="- topic/linktext ">fscommand()</linktext></link></related-links><apiOperation id="flash.external:ExternalInterface:addCallback" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiOperation/apiOperation "><apiName class="- topic/title reference/title apiRef/apiName ">addCallback</apiName><shortdesc class="- topic/shortdesc ">
     将 ActionScript 方法注册为可从容器调用。</shortdesc><prolog class="- topic/prolog "><asMetadata class="+ topic/metadata adobe-api-d/asMetadata "><apiVersion class="+ topic/ph adobe-api-d/apiVersion "><apiLanguage version="3.0" class="+ topic/ph adobe-api-d/apiLanguage "/><apiPlatform description="" name="Flash" version="9" class="+ topic/ph adobe-api-d/apiPlatform "/><apiPlatform description="" name="Lite" version="4" class="+ topic/ph adobe-api-d/apiPlatform "/></apiVersion></asMetadata></prolog><apiOperationDetail class="- topic/body reference/refbody apiRef/apiDetail apiOperation/apiOperationDetail "><apiOperationDef class="- topic/section reference/section apiRef/apiDef apiOperation/apiOperationDef "><apiAccess value="public" class="- topic/state reference/state apiRef/apiQualifier adobe-api-d/apiAccess "/><apiStatic class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiStatic "/><apiException class="+ topic/ph reference/ph apiRef/apiDefItem apiOperation/apiEvent adobe-api-d/apiException "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">此容器不支持传入调用。仅在适用于 Windows 的 Internet Explorer 和使用 NPRuntime API 的浏览器（如 Mozilla 1.7.5 及更高版本或 Firefox 1.0 及更高版本）中支持传入调用。
     
     </apiDesc><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">Error</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">Error</apiOperationClassifier></apiException><apiException class="+ topic/ph reference/ph apiRef/apiDefItem apiOperation/apiEvent adobe-api-d/apiException "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">您无权访问的沙箱中的 ActionScript 已经添加了具有指定名称的回调；您不能覆盖该回调。要解决此问题，请改写原来调用 <codeph class="+ topic/ph pr-d/codeph ">addCallback()</codeph> 方法的 ActionScript，以使其还调用 <codeph class="+ topic/ph pr-d/codeph ">Security.allowDomain()</codeph> 方法。
     
     </apiDesc><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">SecurityError</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">SecurityError</apiOperationClassifier></apiException><apiException class="+ topic/ph reference/ph apiRef/apiDefItem apiOperation/apiEvent adobe-api-d/apiException "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">包含环境属于调用代码无权访问的安全沙箱。要解决此问题，请按照下列步骤操作：
     
     <ol class="- topic/ol "><li class="- topic/li ">在包含 SWF 文件的 HTML 页中，在该文件的 <codeph class="+ topic/ph pr-d/codeph ">object</codeph> 标签中设置以下参数：
     
      <p class="- topic/p "><codeph class="+ topic/ph pr-d/codeph ">&lt;param name="allowScriptAccess" value="always" /></codeph></p>
     
      </li><li class="- topic/li ">在 SWF 文件中，添加以下 ActionScript：
     
      <p class="- topic/p "><codeph class="+ topic/ph pr-d/codeph ">flash.system.Security.allowDomain(<i class="+ topic/ph hi-d/i ">sourceDomain</i>)</codeph></p>
     
      </li></ol>
     
      
      </apiDesc><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">SecurityError</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">SecurityError</apiOperationClassifier></apiException><apiReturn class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiReturn "><apiType value="void" name="type" class="- topic/state reference/state apiRef/apiType "/></apiReturn><apiParam class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiParam "><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">functionName</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">String</apiOperationClassifier><apiDesc class="- topic/section reference/section apiRef/apiDesc ">容器可用于调用函数的名称。
     </apiDesc></apiParam><apiParam class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiParam "><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">closure</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">Function</apiOperationClassifier><apiDesc class="- topic/section reference/section apiRef/apiDesc ">要调用的 closure 函数。这可能是一个独立的函数，或者可能是引用对象实例方法的 closure 方法。通过传递 closure 方法，可以将回调定向到特定对象实例的方法。
                    <p class="- topic/p "><b class="+ topic/ph hi-d/b ">注意：</b>对闭包值为 <codeph class="+ topic/ph pr-d/codeph ">null</codeph> 的现有回调函数重复 <codeph class="+ topic/ph pr-d/codeph ">addCallback()</codeph> 将删除回调。</p>
     
     
     </apiDesc></apiParam></apiOperationDef><apiDesc class="- topic/section reference/section apiRef/apiDesc ">
     将 ActionScript 方法注册为可从容器调用。成功调用 <codeph class="+ topic/ph pr-d/codeph ">addCallBack()</codeph> 后，播放器中注册的函数可由容器中的 JavaScript 或 ActiveX 代码调用。
     
     <p class="- topic/p "><b class="+ topic/ph hi-d/b ">注意：</b>对于在浏览器中运行的<i class="+ topic/ph hi-d/i ">本地</i>内容，仅当 SWF 文件以及包含它的网页位于受信任的本地安全沙箱中时，对 <codeph class="+ topic/ph pr-d/codeph ">ExternalInterface.addCallback()</codeph> 方法的调用才有效。有关详细信息，请参阅 Flash Player 开发人员中心主题：<xref href="http://www.adobe.com/go/devnet_security_cn" scope="external" class="- topic/xref ">安全性</xref>。</p>
     
     </apiDesc></apiOperationDetail><related-links class="- topic/related-links "><link href="flash.system.xml#Security/allowDomain()" class="- topic/link "><linktext class="- topic/linktext ">flash.system.Security.allowDomain()</linktext></link></related-links></apiOperation><apiOperation id="flash.external:ExternalInterface:call" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiOperation/apiOperation "><apiName class="- topic/title reference/title apiRef/apiName ">call</apiName><shortdesc class="- topic/shortdesc "> 
     调用由 SWF 容器公开的函数，传递零个参数或传递多个参数。</shortdesc><prolog class="- topic/prolog "><asMetadata class="+ topic/metadata adobe-api-d/asMetadata "><apiVersion class="+ topic/ph adobe-api-d/apiVersion "><apiLanguage version="3.0" class="+ topic/ph adobe-api-d/apiLanguage "/><apiPlatform description="" name="Flash" version="9" class="+ topic/ph adobe-api-d/apiPlatform "/><apiPlatform description="" name="Lite" version="4" class="+ topic/ph adobe-api-d/apiPlatform "/></apiVersion></asMetadata><asCustoms class="+ topic/metadata adobe-api-d/asCustoms "><internal>Should probably provide a link for the 4th paragraph above for info on Netscape.
     
     </internal></asCustoms></prolog><apiOperationDetail class="- topic/body reference/refbody apiRef/apiDetail apiOperation/apiOperationDetail "><apiOperationDef class="- topic/section reference/section apiRef/apiDef apiOperation/apiOperationDef "><apiAccess value="public" class="- topic/state reference/state apiRef/apiQualifier adobe-api-d/apiAccess "/><apiStatic class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiStatic "/><apiException class="+ topic/ph reference/ph apiRef/apiDefItem apiOperation/apiEvent adobe-api-d/apiException "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">此容器不支持传出调用。仅在适用于 Windows 的 Internet Explorer 和使用 NPRuntime API 的浏览器（如 Mozilla 1.7.5 及更高版本或 Firefox 1.0 及更高版本）中支持传出调用。
     
     </apiDesc><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">Error</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">Error</apiOperationClassifier></apiException><apiException class="+ topic/ph reference/ph apiRef/apiDefItem apiOperation/apiEvent adobe-api-d/apiException "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">包含环境属于调用代码无权访问的安全沙箱。要解决此问题，请按照下列步骤操作：
     
     <ol class="- topic/ol "><li class="- topic/li ">在包含 SWF 文件的 HTML 页中，在该文件的 <codeph class="+ topic/ph pr-d/codeph ">object</codeph> 标签中设置以下参数：
     
      <p class="- topic/p "><codeph class="+ topic/ph pr-d/codeph ">&lt;param name="allowScriptAccess" value="always" /></codeph></p>
     
      </li><li class="- topic/li ">在 SWF 文件中，添加以下 ActionScript：
     
      <p class="- topic/p "><codeph class="+ topic/ph pr-d/codeph ">flash.system.Security.allowDomain(<i class="+ topic/ph hi-d/i ">sourceDomain</i>)</codeph></p>
     
      </li></ol>
	 </apiDesc><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">SecurityError</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">SecurityError</apiOperationClassifier></apiException><apiReturn class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiReturn "><apiDesc class="- topic/section reference/section apiRef/apiDesc ">从容器接收的响应。如果调用失败，则会返回 <codeph class="+ topic/ph pr-d/codeph ">null</codeph> 并引发错误；例如，如果容器中没有此类函数、接口不可用、发生递归（使用 Netscape 或 Opera 浏览器）或出现安全问题。
     
     </apiDesc><apiType value="any" name="type" class="- topic/state reference/state apiRef/apiType "/></apiReturn><apiParam class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiParam "><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">functionName</apiItemName><apiOperationClassifier class="- topic/xref reference/xref apiRef/apiRelation apiOperation/apiOperationClassifier ">String</apiOperationClassifier><apiDesc class="- topic/section reference/section apiRef/apiDesc ">要在容器中调用的函数的字母数字名称。若使用非字母数字函数名称，则将导致出现运行时错误（错误 2155）。可以使用 <codeph class="+ topic/ph pr-d/codeph ">try..catch</codeph> 块处理此错误。
     </apiDesc></apiParam><apiParam class="- topic/ph reference/ph apiRef/apiDefItem apiOperation/apiParam "><apiItemName class="- topic/keyword reference/keyword apiRef/apiItemName ">arguments</apiItemName><apiType value="restParam" name="type" class="- topic/state reference/state apiRef/apiType "/><apiDesc class="- topic/section reference/section apiRef/apiDesc ">传递到容器中的函数的参数。您可以指定零个或多个参数，参数之间用逗号分隔。它们可以是任何 ActionScript 数据类型。如果调用的是 JavaScript 函数，则会自动将 ActionScript 类型转换为 JavaScript 类型；如果调用的是某个其他 ActiveX 容器，则会在请求消息中对参数进行编码。
      
     </apiDesc></apiParam><apiTipTexts><apiTipText class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiTipText ">调用容器中的一个函数。
     
     </apiTipText></apiTipTexts></apiOperationDef><apiDesc class="- topic/section reference/section apiRef/apiDesc "> 
     调用由 SWF 容器公开的函数，传递零个参数或传递多个参数。如果该函数不可用，调用将返回 <codeph class="+ topic/ph pr-d/codeph ">null</codeph>；否则，它返回由该函数提供的值。<i class="+ topic/ph hi-d/i ">不</i>允许在 Opera 或 Netscape 浏览器中使用递归；在这些浏览器上，递归调用将生成 <codeph class="+ topic/ph pr-d/codeph ">null</codeph> 响应。（Internet Explorer 和 Firefox 浏览器上支持递归。）
     
     <p class="- topic/p ">如果该容器是 HTML 页，则此方法在 <codeph class="+ topic/ph pr-d/codeph ">script</codeph> 元素中调用 JavaScript 函数。</p>
     
     <p class="- topic/p ">如果该容器是某个其他 ActiveX 容器，此方法将使用指定的名称调度 FlashCall ActiveX 事件，并且该容器将处理该事件。</p>
     
     <p class="- topic/p ">如果容器承载 Netscape 插件，您可以编写对新 NPRuntime 接口的自定义支持，或嵌入 HTML 控件并在此控件内嵌入播放器。如果嵌入 HTML 控件，可以通过本机容器应用程序的 JavaScript 接口与播放器通信。</p>
     
     <p class="- topic/p "><b class="+ topic/ph hi-d/b ">注意：</b>对于在浏览器中运行的<i class="+ topic/ph hi-d/i ">本地</i>内容，仅当 SWF 文件以及包含它的网页（如果有）位于受信任的本地安全沙箱中时，才允许调用 <codeph class="+ topic/ph pr-d/codeph ">ExternalInterface.call()</codeph> 方法。此外，还可以在包含 SWF 内容的 HTML 页中设置 <codeph class="+ topic/ph pr-d/codeph ">object</codeph> 和 <codeph class="+ topic/ph pr-d/codeph ">embed</codeph> 标签的 <codeph class="+ topic/ph pr-d/codeph ">allowNetworking</codeph> 参数，以防止 SWF 文件使用此方法。有关详细信息，请参阅 Flash Player 开发人员中心主题：<xref href="http://www.adobe.com/go/devnet_security_cn" scope="external" class="- topic/xref ">安全性</xref>。</p>
     
     
     <p class="- topic/p "><b class="+ topic/ph hi-d/b ">关于 Flash Player 应用程序的注意事项：</b>在 Flash Player 10 和 Flash Player 9 Update 5 中，如果启用了弹出窗口阻止程序，某些 Web 浏览器会限制此方法。在这种情况下，只有在响应用户事件（例如，在鼠标单击或按键事件的事件处理函数中）时才能成功调用此方法。</p>
     
     </apiDesc><example conref="examples\ExternalInterface_call_alert.as" class="- topic/example "> 以下示例显示如何使用 ExternalInterface 类 (flash.external.ExternalInterface) 将字符串从 Flash Player 发送到使用 JavaScript alert() 函数在其中显示的 HTML 容器。<xref href="http://actionscriptexamples.com/2008/02/28/using-the-externalinterface-class-in-actionscript-20-and-actionscript-30/" scope="_mmexternal" class="- topic/xref ">ActionScriptExamples.com</xref> 提供的示例。 
<codeblock xml:space="preserve" class="+ topic/pre pr-d/codeblock ">
//
// Requires:
//   - A Flash Professional Label component on the Stage with an instance name of "lbl".
//   - A Flash Professional Button component on the Stage with an instance name of "button".
//
var xmlResponse:String = "&lt;invoke name=\"isReady\" returntype=\"xml\">&lt;arguments>&lt;number>1&lt;/number>&lt;number>" + stage.stageWidth + "&lt;/number>&lt;number>" + stage.stageHeight + "&lt;/number>&lt;/arguments>&lt;/invoke>";
 
lbl.text = "ExternalInterface.available: " + ExternalInterface.available;
lbl.width = 200;
button.enabled = ExternalInterface.available;
button.addEventListener(MouseEvent.CLICK, button_click);
 
function button_click(evt:MouseEvent):void {
    ExternalInterface.call("alert", xmlResponse);
}
</codeblock></example></apiOperationDetail></apiOperation><apiValue id="flash.external:ExternalInterface:marshallExceptions" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiValue/apiValue "><apiName class="- topic/title reference/title apiRef/apiName ">marshallExceptions</apiName><shortdesc class="- topic/shortdesc ">
     表示外部接口是否应尝试将 ActionScript 异常传递到当前浏览器并将 JavaScript 异常传递到播放器。</shortdesc><prolog class="- topic/prolog "><asMetadata class="+ topic/metadata adobe-api-d/asMetadata "><apiVersion class="+ topic/ph adobe-api-d/apiVersion "><apiLanguage version="3.0" class="+ topic/ph adobe-api-d/apiLanguage "/><apiPlatform description="" name="Flash" version="9.0.115.0" class="+ topic/ph adobe-api-d/apiPlatform "/><apiPlatform description="" name="Lite" version="4" class="+ topic/ph adobe-api-d/apiPlatform "/></apiVersion></asMetadata></prolog><apiValueDetail class="- topic/body reference/refbody apiRef/apiDetail apiValue/apiValueDetail "><apiValueDef class="- topic/section reference/section apiRef/apiDef apiValue/apiValueDef "><apiProperty class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiProperty "/><apiAccess value="public" class="- topic/state reference/state apiRef/apiQualifier adobe-api-d/apiAccess "/><apiStatic class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiStatic "/><apiData class="- topic/ph reference/ph apiRef/apiData ">false</apiData><apiValueClassifier class="- topic/xref reference/xref apiRef/apiRelation apiValue/apiValueClassifier ">Boolean</apiValueClassifier><apiTipTexts><apiTipText class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiTipText ">在 AS 和 JS 之间传递异常。     
     </apiTipText></apiTipTexts></apiValueDef><apiDesc class="- topic/section reference/section apiRef/apiDesc ">
     表示外部接口是否应尝试将 ActionScript 异常传递到当前浏览器并将 JavaScript 异常传递到播放器。必须显式将此属性设置为 <codeph class="+ topic/ph pr-d/codeph ">true</codeph>，以便在 ActionScript 中捕获 JavaScript 异常以及在 JavaScript 中捕获 ActionScript 异常。
     
     </apiDesc><example conref="examples\ExternalInterface.marshallExceptions.1.as" class="- topic/example "> 下面的示例创建一个 ActionScript 函数，并使用 <codeph class="+ topic/ph pr-d/codeph ">addCallback()</codeph> 方法向包含它的浏览器进行注册。新函数会引发异常，以便在浏览器中运行的 JavaScript 代码可以捕获该异常。此示例还包含 <codeph class="+ topic/ph pr-d/codeph ">try..catch</codeph> 语句，以便捕获在调用 <codeph class="+ topic/ph pr-d/codeph ">throwit()</codeph> 函数时浏览器引发的任何异常。
<codeblock xml:space="preserve" class="+ topic/pre pr-d/codeblock ">

package
{
    import flash.external.*
    import flash.net.*;
    import flash.display.*;
    import flash.system.System;
    public class ext_test extends Sprite {
    function ext_test():void {
        ExternalInterface.marshallExceptions = true;
        ExternalInterface.addCallback("g", g);

        try {
        ExternalInterface.call("throwit");
        } catch(e:Error) {
        trace(e)
        }
    }
    function g() { throw new Error("exception from actionscript!!!!") }
    }
}
</codeblock></example></apiValueDetail><related-links class="- topic/related-links "><link href="flash.external.xml#ExternalInterface/addCallBack()" class="- topic/link "><linktext class="- topic/linktext ">addCallBack()</linktext></link><link href="../../statements.html#try..catch..finally" class="- topic/link "><linktext class="- topic/linktext ">try..catch..finally 语句</linktext></link></related-links></apiValue><apiValue id="flash.external:ExternalInterface:available:get" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiValue/apiValue "><apiName class="- topic/title reference/title apiRef/apiName ">available</apiName><shortdesc class="- topic/shortdesc ">
     表示此播放器是否位于提供外部接口的容器中。</shortdesc><prolog class="- topic/prolog "><asMetadata class="+ topic/metadata adobe-api-d/asMetadata "><apiVersion class="+ topic/ph adobe-api-d/apiVersion "><apiLanguage version="3.0" class="+ topic/ph adobe-api-d/apiLanguage "/><apiPlatform description="" name="Flash" version="9" class="+ topic/ph adobe-api-d/apiPlatform "/><apiPlatform description="" name="Lite" version="4" class="+ topic/ph adobe-api-d/apiPlatform "/></apiVersion></asMetadata></prolog><apiValueDetail class="- topic/body reference/refbody apiRef/apiDetail apiValue/apiValueDetail "><apiValueDef class="- topic/section reference/section apiRef/apiDef apiValue/apiValueDef "><apiProperty class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiProperty "/><apiAccess value="public" class="- topic/state reference/state apiRef/apiQualifier adobe-api-d/apiAccess "/><apiStatic class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiStatic "/><apiValueAccess value="read" class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiValueAccess "/><apiValueClassifier class="- topic/xref reference/xref apiRef/apiRelation apiValue/apiValueClassifier ">Boolean</apiValueClassifier><apiTipTexts><apiTipText class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiTipText ">表示播放器所在的容器是否提供外部接口。
     
     </apiTipText></apiTipTexts></apiValueDef><apiDesc class="- topic/section reference/section apiRef/apiDesc ">
     表示此播放器是否位于提供外部接口的容器中。如果外部接口可用，则此属性为 <codeph class="+ topic/ph pr-d/codeph ">true</codeph>；否则，为 <codeph class="+ topic/ph pr-d/codeph ">false</codeph>。
     
     <p class="- topic/p "><b class="+ topic/ph hi-d/b ">注意：</b>将外部 API 与 HTML 一起使用时，应始终在尝试调用任何 JavaScript 方法之前检查 HTML 是否已完成加载。</p>
     
     </apiDesc><example class="- topic/example ">下面的示例使用 <codeph class="+ topic/ph pr-d/codeph ">available</codeph> 属性来确定播放器是否位于提供外部接口的容器中。
     <codeblock rev="3.0" xml:space="preserve" class="+ topic/pre pr-d/codeblock ">
     package {
       import flash.text.TextField;
       import flash.display.MovieClip;
       import flash.external.ExternalInterface;
     
       public class extint_test extends MovieClip {
         public function extint_test() {
           var isAvailable:Boolean = ExternalInterface.available;
           var availTxt:TextField = new TextField();
           availTxt.text = isAvailable.toString();
           addChild(availTxt);
         }
       }
     }
     </codeblock>
     
      
      </example></apiValueDetail></apiValue><apiValue id="flash.external:ExternalInterface:objectID:get" ditaarch:DITAArchVersion="1.0" domains="(topic ui-d) (topic hi-d) (topic pr-d) (topic sw-d)                              (topic ut-d) (topic pr-d api-d)" class="- topic/topic reference/reference apiRef/apiRef apiValue/apiValue "><apiName class="- topic/title reference/title apiRef/apiName ">objectID</apiName><shortdesc class="- topic/shortdesc ">
     在 Internet Explorer 中返回 object 标签的 id 属性，或者在 Netscape 中返回 embed 标签的 name 属性。</shortdesc><prolog class="- topic/prolog "><asMetadata class="+ topic/metadata adobe-api-d/asMetadata "><apiVersion class="+ topic/ph adobe-api-d/apiVersion "><apiLanguage version="3.0" class="+ topic/ph adobe-api-d/apiLanguage "/><apiPlatform description="" name="Flash" version="9" class="+ topic/ph adobe-api-d/apiPlatform "/><apiPlatform description="" name="Lite" version="4" class="+ topic/ph adobe-api-d/apiPlatform "/></apiVersion></asMetadata></prolog><apiValueDetail class="- topic/body reference/refbody apiRef/apiDetail apiValue/apiValueDetail "><apiValueDef class="- topic/section reference/section apiRef/apiDef apiValue/apiValueDef "><apiProperty class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiProperty "/><apiAccess value="public" class="- topic/state reference/state apiRef/apiQualifier adobe-api-d/apiAccess "/><apiStatic class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiStatic "/><apiValueAccess value="read" class="+ topic/state reference/state apiRef/apiQualifier adobe-api-d/apiValueAccess "/><apiValueClassifier class="- topic/xref reference/xref apiRef/apiRelation apiValue/apiValueClassifier ">String</apiValueClassifier></apiValueDef><apiDesc class="- topic/section reference/section apiRef/apiDesc ">
     在 Internet Explorer 中返回 <codeph class="+ topic/ph pr-d/codeph ">object</codeph> 标签的 <codeph class="+ topic/ph pr-d/codeph ">id</codeph> 属性，或者在 Netscape 中返回 <codeph class="+ topic/ph pr-d/codeph ">embed</codeph> 标签的 <codeph class="+ topic/ph pr-d/codeph ">name</codeph> 属性。
     </apiDesc></apiValueDetail></apiValue></apiClassifier></apiPackage>