<?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>Bytearray - Programming, Computers and Technology &#187; Javascript</title>
	<atom:link href="http://bytearray.brixtonjunkies.com/category/code/javascript-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://bytearray.brixtonjunkies.com</link>
	<description></description>
	<lastBuildDate>Tue, 03 Nov 2009 11:52:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Flex: ExternalInterface &#8211; The Flex Javascript Bridge</title>
		<link>http://bytearray.brixtonjunkies.com/2009/08/21/flex-externalinterface-the-flex-javascript-bridge/</link>
		<comments>http://bytearray.brixtonjunkies.com/2009/08/21/flex-externalinterface-the-flex-javascript-bridge/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 14:56:51 +0000</pubDate>
		<dc:creator>alchemist</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[externalinterface]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://bytearray.brixtonjunkies.com/?p=53</guid>
		<description><![CDATA[It is really very easy to gain access to Javascript via Flex, the Javascript API is made available via flash.external.ExternalInterface flex class. There are a couple of methods you can use, you can either: Make calls to pre-existing functions (yours or exists JS ones) using the flex ExternalInterface.call function where the argument to call is [...]]]></description>
			<content:encoded><![CDATA[<p>It is really very easy to gain access to Javascript via Flex, the Javascript API is made available via <strong>flash.external.ExternalInterface</strong> flex class. There are a couple of methods you can use, you can either:</p>
<ul>
<li>Make calls to pre-existing functions <em>(yours or exists JS ones)</em> using the flex  <strong>ExternalInterface.call</strong> function where the argument to <strong>call</strong> is a string which represents the normal Javascript function invocation.</li>
<li> Defined a whole Javascript function inside Flex as a string and pass that string to <strong>call</strong>, ExternalInterface.call will then automatically execute the function.</li>
</ul>
<p><em>There is of course no real use in passing in arguments if you are pre-defining the Javascript function as a string because you can just use those value during the generation of the string.<br />
</em></p>
<p><strong>Below is an example of creating and fetching a Javascript cookie, you never know it might come in handy</strong> <img src='http://bytearray.brixtonjunkies.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush: as3; title: ; notranslate">
// ************************ START EXAMPLE *****************************

/**
 * Flex class ExternalInterface does all the magic
 */

import flash.external.ExternalInterface;

public function createCookie(name:String,value:String,days:int=0):void{

    var js:String = &quot;function createCookie(){&quot; +
                     &quot;var expires = '';&quot; +

    &quot;if (&quot; + days + &quot; &gt; 0){&quot; +
        &quot;var date = new Date();&quot; +
        &quot;date.setTime(date.getTime()+(&quot; + days + &quot;*24*60*60*1000));&quot; +
        &quot;expires = 'expires = ' + date.toGMTString();&quot; +
        &quot;}&quot; +
        &quot;document.cookie = '&quot; + name + &quot;=&quot; + value + &quot;; expires=' + expires + '; path=/';&quot; +
    &quot;}&quot;;

    ExternalInterface.call(js);

}

public function getCookie(cookieName:String):String {

   var r:String = &quot;&quot;;

    var search:String = cookieName + &quot;=&quot;;
    var js:String = &quot;function getCookie(){return document.cookie;}&quot;;
    var cookieVariable:String = ExternalInterface.call(js).toString();

    if (cookieVariable.length &gt; 0) {
        var offset:int = cookieVariable.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            var end:int = cookieVariable.indexOf(&quot;;&quot;, offset);
            if (end == -1){
                end = cookieVariable.length;
            }
            r = unescape(cookieVariable.substring(offset, end));
        }
    }

    return r;

}

// ************************ END EXAMPLE *****************************
</pre>
]]></content:encoded>
			<wfw:commentRss>http://bytearray.brixtonjunkies.com/2009/08/21/flex-externalinterface-the-flex-javascript-bridge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

