<?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>nFriedly Web Dev Tech Blog &#187; flashcookie</title>
	<atom:link href="http://nfriedly.com/techblog/tag/flashcookie/feed/" rel="self" type="application/rss+xml" />
	<link>http://nfriedly.com/techblog</link>
	<description>Expert Advice on Website Development, Javascript, Ajax, and Security</description>
	<lastBuildDate>Wed, 01 Feb 2012 22:35:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>JavaScript library and .swf for cross-domain flash cookies</title>
		<link>http://nfriedly.com/techblog/2010/07/swf-for-javascript-cross-domain-flash-cookies/</link>
		<comments>http://nfriedly.com/techblog/2010/07/swf-for-javascript-cross-domain-flash-cookies/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 18:25:11 +0000</pubDate>
		<dc:creator>nFriedly</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[actionscript 3.0]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[cross-domain]]></category>
		<category><![CDATA[externalinterface]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flashcookie]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sharedobject]]></category>
		<category><![CDATA[swf]]></category>

		<guid isPermaLink="false">http://nfriedly.com/techblog/?p=272</guid>
		<description><![CDATA[I&#8217;m working on a project that has a legitimate (non-spammy) reason to need cross-domain cookies, and we settled on flash as a good way to accomplish this. However, I was surprisingly unable to find any complete library or how-to guide for connecting flash cookies to javascript. So I dusted off my flash skills and built [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nfriedly.com/techblog/2010/07/swf-for-javascript-cross-domain-flash-cookies/"><img class="alignright size-full wp-image-295" title="325990_chocolate_chip_cookies_2" src="http://nfriedly.com/techblog/wp-content/uploads/2010/07/325990_chocolate_chip_cookies_2.jpg" alt="" width="300" height="224" /></a>I&#8217;m working on a project that has a legitimate (non-spammy) reason to need cross-domain cookies, and we settled on flash as a good way to accomplish this.</p>
<p>However, I was surprisingly unable to find any complete library or how-to guide for connecting flash cookies to javascript. So I dusted off my flash skills and built one, and decided to share with you the fruits of my labors:</p>
<p><span id="more-272"></span></p>
<p><a href="http://github.com/nfriedly/Javascript-Flash-Cookies"><img style="position: absolute; top: 0pt; right: 0pt; border: 0pt none;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a></p>
<p><a href="http://github.com/nfriedly/Javascript-Flash-Cookies/zipball/master"><img class="alignleft" src="/img/application_put.png" alt="" /> Download the .swf, .js, and source code from github</a></p>
<p>This is an .swf file  that communicates with JavaScript via flash&#8217;s <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html">ExternalInerface</a> to read and write to a Local <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/SharedObject.html">SharedObject</a> (LSO). Essentially, it&#8217;s cross-domain cookies for javascript.</p>
<p>It also includes an (optional) javascript library that handles embedding, communication, error checking, and logging.</p>
<p>The project is hosted at github: <a href="http://github.com/nfriedly/Javascript-Flash-Cookies">http://github.com/nfriedly/Javascript-Flash-Cookies</a></p>
<hr style="margin-top: 20px;" />
<p><em>You might also be interested in <a href="http://nfriedly.com/techblog/2010/08/how-facebook-sets-and-uses-cross-domain-cookies/">How Facebook Sets and uses cross-Domain cookies</a></em></p>
<hr />
<h3>Working Example</h3>
<p>See <a href="http://nfriedly.com/stuff/swfstore-example/">http://nfriedly.com/stuff/swfstore-example/</a> and <a href="http://nfriedly.github.com/Javascript-Flash-Cookies/">http://nfriedly.github.com/Javascript-Flash-Cookies/</a> for a working example. </p>
<h3>Quick start guide</h3>
<p>To use the library, upload the storage.swf &amp; swfstore.js files to your web server and put this HTML and JavaScript into your web page(s):</p>
<h4>The HTML</h4>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- this example uses jquery, but SwfStore does not require jquery to work. --&gt;
&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;/PATH/TO/swfstore.js&quot;&gt;&lt;/script&gt;

&lt;input id=&quot;dataInput&quot; /&gt; &lt;input id=&quot;saveBtn&quot; type=&quot;submit&quot; value=&quot;Save&quot; /&gt;
</pre>
<h4>And The JavaScript</h4>
<pre class="brush: jscript; title: ; notranslate">

// wait until the page has finished loading before starting
$(function(){

	// first disable things while the swfStore is initializing
	$('input').attr(&quot;disabled&quot;,&quot;disabled&quot;);
	$('#status').text('Loading...');

	var mySwfStore = new SwfStore({

		// the this must match all other instances that want to share cookies
		namespace: 'myExample', 

		// to work cross-domain, only one of your sites should have the .swf
		// all other sites should load it from the first one
		swf_url: 'http://site.com/PATH/TO/storage.swf', 

		// logs messages to the console if available, a div at the bottom of
		// the page otherwise.
		debug: true,

		onready: function(){
			// now that the swfStore was loaded successfully, re-enable
			$('input').removeAttr(&quot;disabled&quot;);
			$('#status').text('Loaded');

			// read the existing value (if any)
			$('#dataInput').val(mySwfStore.get('myKey'));

			// set up an onclick handler to save the text to the swfStore
			// whenever the Save button is clicked
			$('#saveBtn').click(function(){
				mySwfStore.set('myKey', $('#dataInput').val() );
				$('#status').text('Saved!')
			});
		},

		onerror: function(){
			// in case we had an error. (The most common cause is that
			// the user disabled flash cookies.)
			$('#status').text('Error');
		}
	});
});
</pre>
<h3>Cross-domain usage</h3>
<p>A copy of storage.swf located on one domain may be embedded on pages from one or more other domains, allowing cross-domain cookie access.</p>
<h3>Troubleshooting</h3>
<ul>
<li>Be sure the urls to the .swf file and .js file are both correct.</li>
<li>If the .swf file is unable to communicate with the JavaScript, it will display log messages on the flash object. If debug is enabled, this this should be visible on the page.</li>
<li>Alternatively, if you want to hide the flash object, set debug to false.</li>
<li>If the user does not have flash installed,  the onerror function will be called after a (configurable) 10 second timeout. You may want to use a library such as <a href="http://www.featureblend.com/javascript-flash-detection-library.html">Flash Detect</a> to check for this more quickly. Flash Player 9.0.31.0 or newer is required.</li>
<li>If you pass a non-string data as the key or value, things may break. Your best bet is to use strings and/or use <a href="http://json.org">JSON</a> to encode objects as strings.</li>
<li>Be sure to disable debug mode when pushing to production. Log messages are appended to the bottom of the page in debug mode if no console is found.</li>
</ul>
<h3>Patches</h3>
<p>Although my JS is solid, my Flash / ActionScript skills leave something to be desired. Patches to either are more than welcome at <a href="http://github.com/nfriedly/Javascript-Flash-Cookies">github</a> (preferred), or just leave a comment here if you&#8217;re not sure how to use github. (This comment has a <a href="http://nfriedly.com/techblog/2010/07/swf-for-javascript-cross-domain-flash-cookies/comment-page-1/#comment-2531">short walk through to using github</a>.)</p>
<h3>Production Use</h3>
<p>If you&#8217;re using SwfStore in a production site, feel free to leave a comment here with a link to the site. I turned off WP&#8217;s default rel=&#8221;nofollow&#8221;, so enjoy the link juice <img src='http://nfriedly.com/techblog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Reciprocal links are not required, but are, of course, appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://nfriedly.com/techblog/2010/07/swf-for-javascript-cross-domain-flash-cookies/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
	</channel>
</rss>

