<?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"
	>

<channel>
	<title>Codeplague &#187; Javascript</title>
	<atom:link href="http://blog.codeplague.org/category/programming/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codeplague.org</link>
	<description>When coding becomes the plague</description>
	<pubDate>Mon, 14 Apr 2008 04:02:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Javascript and Flex Communication</title>
		<link>http://blog.codeplague.org/2008/04/11/javascript-and-flex-communication/</link>
		<comments>http://blog.codeplague.org/2008/04/11/javascript-and-flex-communication/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 05:10:22 +0000</pubDate>
		<dc:creator>wesw02</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Communication]]></category>

		<guid isPermaLink="false">http://blog.codeplague.org/?p=7</guid>
		<description><![CDATA[A couple days a go I was writing a quick flex app at work and it became necessary for me to be able communicate between javascript and flex, that is, making javascript calls from flex and making flex calls from javascript. After a bit of research, I found that it is a pretty easy thing [...]]]></description>
			<content:encoded><![CDATA[<p>A couple days a go I was writing a quick flex app at work and it became necessary for me to be able communicate between javascript and flex, that is, making javascript calls from flex and making flex calls from javascript. After a bit of research, I found that it is a pretty easy thing to do. To make it easier to see what is going on I&#8217;m splitting this up into two separate examples.</p>
<p>Making javascript calls from flex:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript">&lt;?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;iso-8859-1&quot;</span>?&gt;
&lt;mx:Application xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;86&quot;</span> layout=<span style="color: #ff0000;">&quot;absolute&quot;</span>  &gt;
    &lt;mx:Script&gt;
    	&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
        	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">external</span>.<span style="color: #006600;">*</span>;
&nbsp;
    		<span style="color: #000000; font-weight: bold;">function</span> buttonClicked<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    			ExternalInterface.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;alert&quot;</span>, userInputField.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#41;</span>;
    		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>&gt;
    &lt;/mx:Script&gt;
&nbsp;
	&lt;mx:TextInput id=<span style="color: #ff0000;">&quot;userInputField&quot;</span> x=<span style="color: #ff0000;">&quot;20&quot;</span> y=<span style="color: #ff0000;">&quot;28&quot;</span>  <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;191&quot;</span>/&gt;
	&lt;mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;JS Alert&quot;</span> click=<span style="color: #ff0000;">&quot;buttonClicked()&quot;</span>  x=<span style="color: #ff0000;">&quot;219&quot;</span> y=<span style="color: #ff0000;">&quot;28&quot;</span>/&gt;
&lt;/mx:Application&gt;</pre></div></div>

<p>
<object type="application/x-shockwave-flash" data="http://blog.codeplague.org/content/Flex_JS_Communication/flexInvokeJs.swf" width="300" height="86">
	<param name="movie" value="http://blog.codeplague.org/content/Flex_JS_Communication/flexInvokeJs.swf" />
	<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Get FlashPlayer</a>
</object>
</p>
<p>The above example makes a simple call to the javascript function &#8220;alert&#8221; and passes the text in the text field as an argument to the alert function. To pass more than one argument simply just add them as additional arguments to the ExternalInterface.call() method. Example: ExternalInterface.call(&#8221;myJsFunction&#8221;, &#8220;arg1&#8243;, &#8220;arg2&#8243;);</p>
<hr />
<p>Making flex calls from javascript:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript">&lt;?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;iso-8859-1&quot;</span>?&gt;
&lt;mx:Application xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;86&quot;</span> layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span> &gt;
    &lt;mx:Script&gt;
    	&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
        	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">external</span>.<span style="color: #006600;">*</span>;
&nbsp;
    		<span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    			ExternalInterface.<span style="color: #006600;">addCallback</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;setTextField&quot;</span>, setTextField<span style="color: #66cc66;">&#41;</span>;
    		<span style="color: #66cc66;">&#125;</span>
&nbsp;
    		<span style="color: #000000; font-weight: bold;">function</span> setTextField<span style="color: #66cc66;">&#40;</span>userInput:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    			userInputField.<span style="color: #0066CC;">text</span> = userInput;
    		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>&gt;
    &lt;/mx:Script&gt;
&nbsp;
	&lt;mx:TextInput id=<span style="color: #ff0000;">&quot;userInputField&quot;</span> x=<span style="color: #ff0000;">&quot;20&quot;</span> y=<span style="color: #ff0000;">&quot;28&quot;</span>  <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;191&quot;</span>/&gt;
&lt;/mx:Application&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">var</span> flexApp;
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>navigator.<span style="color: #006600;">userAgent</span>.<span style="color: #006600;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;MSIE&quot;</span><span style="color: #66cc66;">&#41;</span> != <span style="color: #CC0000;">-1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	flexApp = window<span style="color: #66cc66;">&#91;</span>flexElementObjectId<span style="color: #66cc66;">&#93;</span>;
<span style="color: #66cc66;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span>
	flexApp = document<span style="color: #66cc66;">&#91;</span>flexElementObjectId<span style="color: #66cc66;">&#93;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
flexApp.<span style="color: #006600;">setTextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;Hello World&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This example invokes a flex function from javascript. As you may have noticed this is relatively simple, all you need to do is add a an external callback within flex and make a call to the DOM object from Javascript.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codeplague.org/2008/04/11/javascript-and-flex-communication/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://blog.codeplague.org/2007/12/21/hello-world/</link>
		<comments>http://blog.codeplague.org/2007/12/21/hello-world/#comments</comments>
		<pubDate>Fri, 21 Dec 2007 22:56:35 +0000</pubDate>
		<dc:creator>wesw02</dc:creator>
		
		<category><![CDATA[C/C++]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.codeplague.com/?p=1</guid>
		<description><![CDATA[
&#60;script type=&#34;text/javascript&#34;&#62;
  alert&#40;'Hello World!'&#41;;
&#60;/script&#62;


&#60;?php
  echo &#34;Hello World!&#34;;
?&#62;


public class HelloWorld &#123;
  public static void main&#40;String&#91;&#93; args&#41; &#123;
    System.out.println&#40;&#34;Hello World!&#34;&#41;;
  &#125;
&#125;


#include &#60;iostream&#62;
&#160;
int main&#40;&#41;
&#123;
  std::cout &#60;&#60; &#34;Hello World!&#34; &#60;&#60; std::endl;
  return 0;
&#125;

You get the idea.
]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="javascript">&lt;script type=<span style="color: #3366CC;">&quot;text/javascript&quot;</span>&gt;
  <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Hello World!'</span><span style="color: #66cc66;">&#41;</span>;
&lt;/script&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;Hello World!&quot;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HelloWorld <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> args<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Hello World!&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cpp"><span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  std::<span style="color: #0000dd;">cout</span> &lt;&lt; <span style="color: #666666;">&quot;Hello World!&quot;</span> &lt;&lt; std::<span style="color: #00eeff;">endl</span>;
  <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>You get the idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codeplague.org/2007/12/21/hello-world/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
