<?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>Simplistika &#187; Actionscript</title>
	<atom:link href="http://simplistika.com/tag/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://simplistika.com</link>
	<description>Think Simple</description>
	<lastBuildDate>Thu, 13 May 2010 11:48:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>AS3 Javascript Communication</title>
		<link>http://simplistika.com/as3-javascript-communication/</link>
		<comments>http://simplistika.com/as3-javascript-communication/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 13:56:45 +0000</pubDate>
		<dc:creator>jared</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://jared.simplistika.com/?p=162</guid>
		<description><![CDATA[I was searching high and low for a solid example of how Javascript and AS3 talk to each other, and couldn&#8217;t really find one, so here it is. See the example here. Actionscript 3 to Javascript In this example we&#8217;ll use Javascript to create a popup window from Flash. If you click on the &#8220;Pop [...]]]></description>
			<content:encoded><![CDATA[<p>I was searching high and low for a solid example of how Javascript and AS3 talk to each other, and couldn&#8217;t really find one, so here it is.</p>
<p><a href="http://www.simplistika.com/files/javascriptpop/JavascriptPopup.html"><img class="alignnone size-full wp-image-172" title="javascript actionscript 3" src="http://simplistika.com/wp-content/uploads/2008/10/scjpp.jpg" alt="" width="225" height="116" /></a><br />
<a href="http://www.simplistika.com/files/javascriptpop/JavascriptPopup.html">See the example here</a>.</p>
<p><strong>Actionscript 3 to Javascript</strong></p>
<p>In this example we&#8217;ll use Javascript to create a popup window from Flash.</p>
<p>If you click on the &#8220;Pop up!&#8221; button, the following code from JavascriptPopup.fla is executed inside the click button event handler.</p>
<pre lang="actionscript">var jscommand:String = "window.open
('http://jared.simplistika.com','win','height=170,width=350,
toolbar=no,scrollbars=yes');";
var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
navigateToURL(url, "_self");</pre>
<p>Only thing is if you do a CTRL + Enter locally on your computer, nothing will work. To test it you&#8217;ll have to upload it to a server which I&#8217;ve done here. Pretty easy to just replace your own Javascript from here on.</p>
<p><strong>Javascript to Actionscript 3</strong></p>
<p>Still inside JavascriptPopup.fla, we have</p>
<pre>ExternalInterface.addCallback("changeText", changeTheText);</pre>
<p>which basically sets up Flash to communicate with the HTML page. Two things to note:</p>
<p><strong>changeText</strong> refers to the Javascript function we will be calling from the HTML. Give this any name you want but remember it because we&#8217;ll be using it later.</p>
<p><strong>changeTheText</strong> refers to the Actionscript function which is exactly right below that line of code.</p>
<pre>function changeTheText(t:String):void {
	txtText.text = t;
}</pre>
<p>And what this function does is simply set up the textbox in our Flash project named <strong>txtText</strong> to a String value which will be sent via Javascript later on.</p>
<p>And so to set up the link in our HTML page, we use this line</p>
<p>&lt;p&gt;&lt;a href=&#8221;#&#8221; onClick=&#8221;JavascriptPopup.changeText(&#8216;it works!&#8217;);&#8221;&gt;Click me!&lt;/a&gt;&lt;/p&gt;</p>
<p>Where <em>JavascriptPopup</em> refers to the <em>id</em> (look for an id attribute in the generated HTML file) of your flash movie, in this case it is JavascriptPopup, changeText is our function defined earlier, and <em>&#8216;it works!&#8217;</em> is our text that we are sending into Flash.</p>
<p><a href="http://www.simplistika.com/files/javascriptpop/javascriptas3.zip">Click here to download files in this example</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://simplistika.com/as3-javascript-communication/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>
