<?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>风牛菜籽 &#187; as3</title>
	<atom:link href="http://www.caiyanpei.com/tag/as3-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.caiyanpei.com</link>
	<description>拖延症重症患者</description>
	<lastBuildDate>Tue, 25 Mar 2025 01:51:19 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.6.1</generator>
		<item>
		<title>Flash和JavaScript互相调用</title>
		<link>http://www.caiyanpei.com/flash-javascript-incall/</link>
		<comments>http://www.caiyanpei.com/flash-javascript-incall/#comments</comments>
		<pubDate>Thu, 22 Nov 2012 13:59:40 +0000</pubDate>
		<dc:creator>tsai</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[as3]]></category>

		<guid isPermaLink="false">http://www.xiuchezu.com/?p=528</guid>
		<description><![CDATA[1.Flash调用JavaScript中的方法 ExternalInterfac &#8230; <a href="http://www.caiyanpei.com/flash-javascript-incall/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>1.Flash调用JavaScript中的方法<br />
ExternalInterface.call(&#8220;js方法名&#8221;,“方法入参”);</p>
<p>2.JavaScript调用Flash中的方法<br />
Flash中注册ExternalInterface.addCallback(&#8220;供js调用的方法&#8221;, flash方法);</p>
<p>例子：</p>
<p>exp.html</p>
<pre class="brush: xml; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;swfobject demo&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;swfobject.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
function jsAlert(txt)
{
alert(txt);
}
function flashAlert()
{
var obj = document.getElementById(&quot;demo&quot;);
obj.flashAlert();
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;content&quot;&gt;
NO Flash Player or NO Support This Flash Player!
&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var so = new SWFObject(&quot;Testjs.swf&quot;, &quot;demo&quot;, &quot;640&quot;, &quot;480&quot;, &quot;10&quot;, &quot;#000000&quot;);
so.addParam(&quot;wmode&quot;, &quot;transparent&quot;);
so.addParam(&quot;allowFullScreen&quot;, &quot;true&quot;);
so.write(&quot;content&quot;);
&lt;/script&gt;
&lt;input type=&quot;Button&quot; value=&quot;警告&quot; onclick=&quot;flashAlert()&quot;/&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>exp.mxml</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;&lt;a href=&quot;http://www.adobe.com/2006/mxml&quot; rel=&quot;nofollow&quot;&gt;http://www.adobe.com/2006/mxml&lt;/a&gt;&quot; layout=&quot;absolute&quot; creationComplete=&quot;init()&quot;&gt;
&lt;mx:Script&gt;
&lt;![CDATA[
import mx.controls.Alert;
import flash.external.ExternalInterface;
private function init():void
{
ExternalInterface.addCallback(&quot;flashAlert&quot;, flashAlertTest);
}
private function doAlert(evt:Event):void
{
ExternalInterface.call(&quot;jsAlert&quot;, &quot;js Alert&quot;);
}
private function flashAlertTest():void
{
Alert.show(&quot;flash Alert&quot;);
}
]]&gt;
&lt;/mx:Script&gt;
&lt;mx:Button x=&quot;36&quot; y=&quot;97&quot; label=&quot;提示&quot; click=&quot;doAlert(event)&quot;/&gt;
&lt;mx:Label x=&quot;36&quot; y=&quot;64&quot; text=&quot;Flash调用js&quot; width=&quot;135&quot; height=&quot;25&quot;/&gt;
&lt;/mx:Application&gt;
</pre>
<p><span style="color: #ff0000;">注意：<br />
1. exp.html, exp.mxml, swfobject.js必须放到web服务器中，直接在本地打开，会出错：SecurityError:Error #2060:安全沙箱冲突:ExternalInterface调用者&#8230;</span></p>
<p><span style="color: #ff0000;">2. ExternalInterface.addCallback(&#8220;flashAlert&#8221;, flashAlertTest); 必须包含在方法中，然后触发它；否则，会出错：1120:访问的属性flashAlertTest未定义。<br />
如：</span></p>
<pre class="brush: as3; title: ; notranslate">
private function init():void
{
ExternalInterface.addCallback(&quot;flashAlert&quot;, flashAlertTest);
}

init();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.caiyanpei.com/flash-javascript-incall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
