<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>omiga &#187; EI</title>
	<atom:link href="http://omiga.org/blog/archives/tag/ei/feed" rel="self" type="application/rss+xml" />
	<link>http://omiga.org/blog</link>
	<description>简单就好</description>
	<lastBuildDate>Thu, 26 Apr 2012 04:18:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>ExternalInterface</title>
		<link>http://omiga.org/blog/archives/1118</link>
		<comments>http://omiga.org/blog/archives/1118#comments</comments>
		<pubDate>Thu, 23 Jul 2009 09:16:23 +0000</pubDate>
		<dc:creator>omiga</dc:creator>
				<category><![CDATA[前端开发]]></category>
		<category><![CDATA[AS]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[EI]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[ExternalInterfaceas]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://omiga.org/blog/?p=1118</guid>
		<description><![CDATA[ExternalInterface是一个外部的用于实现Actionscript和Flash Player容器之间通信的应用程序接口（诸如AS与JS的通信）。推荐对所有 JavaScript 与 ActionScript 之间的通信使用 ExternalInterface，替代较旧的fscommand()，getURL()方法。 ExternalInterface类有两个公共属性： available : Boolean　[static][read-only]　指示此播放器是否位于提供外部接口的容器中。 objectID : String　[static][read-only]　在 Internet Explorer 中，返回标签的 id 属性；在 Netscape 中，返回 name 属性。 同时具有两个公共方法： addCallback(functionName:String, closure:Function):void　[static]　将 ActionScript 方法注册为可从容器调用。 call(functionName:String, … arguments):*　[static]　调用由 Flash Player 容器公开的函数，不传递参数或传递多个参数。 ActionScript调用JavaScript demo AS: import flash.events.MouseEvent; import flash.external.ExternalInterface; bt.addEventListener(MouseEvent.MOUSE_UP,alert); function alert(e:MouseEvent):void{ ExternalInterface.call("alert","a demo for call \n http://omiga.org"); } 直接调用即可,当然,最好检查一下当前容器是否支持外部接口通信。 bt.addEventListener(MouseEvent.MOUSE_UP,alert); function alert(e:MouseEvent):void{ [...]]]></description>
			<content:encoded><![CDATA[<p>ExternalInterface是一个外部的用于实现Actionscript和Flash Player容器之间通信的应用程序接口（诸如AS与JS的通信）。推荐对所有 JavaScript 与 ActionScript 之间的通信使用 ExternalInterface，替代较旧的fscommand()，getURL()方法。</p>
<p>ExternalInterface类有两个公共属性：</p>
<ol>
<li>available : Boolean　[static][read-only]　指示此播放器是否位于提供外部接口的容器中。</li>
<li>objectID : String　[static][read-only]　在 Internet Explorer 中，返回标签的 id 属性；在 Netscape 中，返回 name 属性。</li>
</ol>
<p>同时具有两个公共方法：</p>
<ol>
<li>addCallback(functionName:String, closure:Function):void　[static]　将 ActionScript 方法注册为可从容器调用。</li>
<li>call(functionName:String, … arguments):*　[static]　调用由 Flash Player 容器公开的函数，不传递参数或传递多个参数。</li>
</ol>
<p><strong>ActionScript调用JavaScript</strong> <a href="../../lab/call/call.html" target="_blank">demo</a></p>
<p>AS:</p>
<pre>import flash.events.MouseEvent;
import flash.external.ExternalInterface;
bt.addEventListener(MouseEvent.MOUSE_UP,alert);
function alert(e:MouseEvent):void{
 ExternalInterface.call("alert","a demo for call \n http://<strong>omiga</strong>.org");
}</pre>
<p>直接调用即可,当然,<span style="font-family: comic sans ms,sans-serif;">最好检查一下当前容器是否支持外部接口通信。</span></p>
<pre>bt.addEventListener(MouseEvent.MOUSE_UP,alert);
function alert(e:MouseEvent):void{
 if(ExternalInterface.available){
 ExternalInterface.call("alert","a demo for call \n http://<strong>omiga</strong>.org");
 }
}</pre>
<p><strong>JavaScript调用ActionScript</strong> <a href="../../lab/call/addcallback.html" target="_blank">demo</a></p>
<p>AS:</p>
<pre>import flash.external.ExternalInterface;
function setText(s){
 i_txt.text = s;
}
ExternalInterface.addCallback("setText",setText);</pre>
<p>HTML:</p>
<pre>&lt;object id="mySWF"  classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="300" height="22"&gt;
 &lt;param name="movie" value="addCallback.swf" /&gt;
 &lt;param name="quality" value="high" /&gt;
 &lt;param name="allowScriptAccess" value="always" /&gt;
 &lt;embed src="addCallback.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="300" height="22"&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;button onclick="set()"&gt;设 置&lt;/button&gt;
&lt;script type="text/javascript"&gt;
function getFlash(id){
 if(document.all) return document.getElementById(id);
 else return document.getElementById(id).getElementsByTagName("embed")[0];
}
function set(){
 var s = prompt('请输入：');
 getFlash("mySWF").setText(s);
}
&lt;/script&gt;</pre>
<hr />
<p><small>© omiga for <a href="http://omiga.org/blog">omiga</a>, 2009. |
<a href="http://omiga.org/blog/archives/1118">Permalink</a> |
<a href="http://omiga.org/blog/archives/1118#comments">No comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://omiga.org/blog/archives/1118&title=ExternalInterface">del.icio.us</a>
<br/>
Post tags: <a href="http://omiga.org/blog/archives/tag/as" rel="tag">AS</a>, <a href="http://omiga.org/blog/archives/tag/as3" rel="tag">AS3</a>, <a href="http://omiga.org/blog/archives/tag/ei" rel="tag">EI</a>, <a href="http://omiga.org/blog/archives/tag/externalinterface" rel="tag">ExternalInterface</a>, <a href="http://omiga.org/blog/archives/tag/externalinterfaceas" rel="tag">ExternalInterfaceas</a>, <a href="http://omiga.org/blog/archives/tag/flash" rel="tag">flash</a>, <a href="http://omiga.org/blog/archives/tag/javascript" rel="tag">javascript</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://omiga.org/blog/archives/1118/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

