<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Magp.ie &#187; LSO</title>
	<atom:link href="http://magp.ie/tag/lso/feed/" rel="self" type="application/rss+xml" />
	<link>http://magp.ie</link>
	<description>A nest for the random, shiny, online tidbits I stumble across...</description>
	<lastBuildDate>Tue, 31 Jan 2012 19:01:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='magp.ie' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/061e340c5da13b5a41ae8016bee03aa8?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Magp.ie &#187; LSO</title>
		<link>http://magp.ie</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://magp.ie/osd.xml" title="Magp.ie" />
	<atom:link rel='hub' href='http://magp.ie/?pushpress=hub'/>
		<item>
		<title>Javascript library to manage Flash Local Stored Objects</title>
		<link>http://magp.ie/2010/10/15/javascript-library-to-manage-flash-local-stored-objects/</link>
		<comments>http://magp.ie/2010/10/15/javascript-library-to-manage-flash-local-stored-objects/#comments</comments>
		<pubDate>Fri, 15 Oct 2010 18:40:25 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[cross-browser]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[LSO]]></category>
		<category><![CDATA[same origin policy]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=236</guid>
		<description><![CDATA[In an earlier post, I explained how to use Javascript to talk to a Flash file to create and read Local stored objects, a.k.a. Flash cookies. The only hitch I met was that I couldn&#8217;t create cross domain cookies this &#8230; <a href="http://magp.ie/2010/10/15/javascript-library-to-manage-flash-local-stored-objects/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&amp;blog=11708208&amp;post=236&amp;subd=blogalhost&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In an <a href="http://magp.ie/2010/03/22/javascript-externalinterface-flash-and-local-shared-objects/">earlier post</a>, I explained how to use Javascript to talk to a Flash file to create and read Local stored objects, a.k.a. Flash cookies.</p>
<p>The only hitch I met was that I couldn&#8217;t create cross domain cookies this way as I was hitting the <a href="http://www.w3.org/Security/wiki/Same_Origin_Policy">same domain policy</a>. However as pointed out in the comments, it is possible, and simple too&#8230; I just needed to add&#8230;<span id="more-236"></span></p>
<p><code>Security.allowDomain("*");</code></p>
<p>Well, as I was editing my simple library, I came across a gem of a Javascript library that is better written and was <a href="http://github.com/nfriedly/Javascript-Flash-Cookies">open sourced</a>.<br />
The library can be found on the site, <a href="http://nfriedly.com/techblog/2010/07/swf-for-javascript-cross-domain-flash-cookies/">nfriedly.com</a>.</p>
<p>Couple of points, you should probably use some flash detection when working with this as it uses Actionscript 3.0. This is only available from Flash version 9.0.31. I used <a href="http://www.featureblend.com/javascript-flash-detection-library.html">featureblend.com</a>&#8216;s most excellent <a href="http://www.featureblend.com/flash_detect_1-0-4/flash_detect_min.js">compressed Javascript library</a>.</p>
<p>Depending on your usage of the library, you may need to edit the Javascript to fix a couple of bugs. The library uses document.body.appendChild() which when used while dynamically loading the library, will <a href="http://support.microsoft.com/kb/927917">cause Internet Explorer 7 to calf.</a></p>
<p>Simple fix is to either use document.write to insert a div into the dom and use this element or use an existing one to append to.</p>
<p>Also found while using dynamic loading, that if there is a timeout caused (from not being able to connect to the Flash file) and the SwfStore object is not initialized, it will throw an error as it tries to access the SwfStore methods. </p>
<p>Another simple fix is to add a check that it is defined&#8230; </p>
<p><pre class="brush: plain;">this._timeout = setTimeout(function () {
            if ( typeof SwfStore!==&quot;undefined&quot; &amp;&amp; typeof SwfStore[namespace]!==&quot;undefined&quot; ) {
            	SwfStore[namespace].log('Timeout reached, assuming the store.swf failed to load and firing the onerror callback.');
            	if ( typeof SwfStore[namespace].config.onerror !== &quot;undefined&quot; ){
            		SwfStore[namespace].config.onerror();
            	}
            }
        }, timeout * 1000);</pre></p>
<p>Anyways, love coming across libraries like this as it saves me a bunch of time. Check it out, it&#8217;s almost certainly what you need <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />Filed under: <a href='http://magp.ie/category/guides/'>Guides</a> Tagged: <a href='http://magp.ie/tag/cookies/'>cookies</a>, <a href='http://magp.ie/tag/cross-browser/'>cross-browser</a>, <a href='http://magp.ie/tag/externalinterface/'>ExternalInterface</a>, <a href='http://magp.ie/tag/flash/'>Flash</a>, <a href='http://magp.ie/tag/javascript/'>javascript</a>, <a href='http://magp.ie/tag/lso/'>LSO</a>, <a href='http://magp.ie/tag/same-origin-policy/'>same origin policy</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/236/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&amp;blog=11708208&amp;post=236&amp;subd=blogalhost&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2010/10/15/javascript-library-to-manage-flash-local-stored-objects/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>
	</item>
		<item>
		<title>JavaScript, ExternalInterface, Flash and Local Shared Objects</title>
		<link>http://magp.ie/2010/03/22/javascript-externalinterface-flash-and-local-shared-objects/</link>
		<comments>http://magp.ie/2010/03/22/javascript-externalinterface-flash-and-local-shared-objects/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 10:28:00 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[DOM storage]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Local Shared Objects]]></category>
		<category><![CDATA[LSO]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=141</guid>
		<description><![CDATA[I was looking into flash&#8217;s local shared objects ( from here on LSO&#8217;s ) recently as a method of data persistence on a clients browser as the plain old HTTP cookie has its limitations. LSO&#8217;s are like cookies and are &#8230; <a href="http://magp.ie/2010/03/22/javascript-externalinterface-flash-and-local-shared-objects/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&amp;blog=11708208&amp;post=141&amp;subd=blogalhost&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was looking into flash&#8217;s local shared objects ( from here on LSO&#8217;s ) recently as a method of data persistence on a clients browser as the plain old HTTP cookie has its limitations.</p>
<p>LSO&#8217;s are like cookies and are sometimes referred to flash cookies but there are 2 main differences between them. A normal HTTP cookie can store around 4k of data, while the flash cookie can store up to 100k. Also a normal cookie is pretty easy to remove while removing a flash cookie is far more convoluted, which is a matter of some contention.<br />
<span id="more-141"></span><br />
<strong>HANDY TIP:</strong> Removing LSO&#8217;s from your computer<br />
You can remove LSO&#8217;s using a tool on Adobe site, <a target="_blank" href="http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager07.html">here</a>, which also allows you to configure your flash security settings. You can also install a Firefox plugin, <a target="_blank" href="http://objection.mozdev.org/">Objection</a>, which will allow you to see and remove whatever flash cookies are present on your computer.</p>
<p>I wanted to set a flash cookie using JavaScript. This is pretty straightforward thanks to Flash&#8217;s ExternalInterface class. This class allows you to set methods that can be accessed from an external script, like JavaScript. This class is bi-directional, so you can also call JavaScript methods from within the Flash&#8217;s ActionScript.</p>
<p>I used the site, <a target="_blank" href="http://www.viget.com/inspire/bi-directional-actionscript-javascript-communication">viget</a> and <a target="_blank" href="http://www.peachpit.com/guides/content.aspx?g=flash&amp;seqNum=340">peachpit</a>, to get an idea how to set this up and found some excellent, quirky tips from the <a target="_blank" href="http://www.schillmania.com/">schillmania</a> site.</p>
<p>On my web page I needed to reference a neat <a target="_blank" href="http://code.google.com/p/swfobject/">SWFObject</a> class to embed a flash player on the page. Once I had a handle on the flash player, I can call the Flash file&#8217;s ActionScript methods to request and set the LSO. The <a target="_blank" href="http://www.actionscript.org/resources/articles/118/1/SharedObjects/Page1.html">actionscript.org</a> site has a good tutorial on how to manage LSO&#8217;s using ActionScript.</p>
<p>So here&#8217;s the JavaScript&#8230;</p>
<p><pre class="brush: jscript;">
var lso_value;

function init() {
	var so = new swfobject.embedSWF(&quot;pd_check.swf&quot;, &quot;pd_check&quot;, &quot;1&quot;, &quot;1&quot;, &quot;9.0.0&quot;);
	so.write(&quot;flash_container&quot;);
}

function getFlashMovie( movieName ) {
	var isIE = navigator.appName.indexOf(&quot;Microsoft&quot;) != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function requestLSOValue() {
	getFlashMovie('pd_check').requestLSOValue();
}

function updateLSOValue( value ) {
	lso_value = value;
}

function setLSOValue( value ) {
	getFlashMovie('pd_check').setLSOValue( value );
}
</pre></p>
<p>&#8230; and here&#8217;s the ActionScript. You can remove the console.log lines if you wish, they were just initially helpful in knowing what was going on under the flash hood.</p>
<p><pre class="brush: as3;">
import flash.external.ExternalInterface;
//call from javascript
ExternalInterface.addCallback( &quot;requestLSOValue&quot;, requestLSOValue );
ExternalInterface.addCallback( &quot;setLSOValue&quot;, setLSOValue );

function requestLSOValue():void 
{	
	try
	{
		ExternalInterface.call('console.log', 'Trace: requestLSOValue');
		var obj_value:String = '0';
		var lso=SharedObject.getLocal(&quot;pd_check&quot;);
	
		// If name variable is not available, we assume that this is a new user
		if (lso.data.value!=null)
		{
		  obj_value = lso.data.value;
		}
		if (ExternalInterface.available) {
			ExternalInterface.call('console.log', 'Trace: getLSOValue::' + obj_value);
			ExternalInterface.call(&quot;updateLSOValue&quot;, obj_value );
		}
	}
	catch(e) {
		ExternalInterface.call('console.log', 'Flash error: '+e.toString());
	}
}

function setLSOValue( obj_value ):void 
{	
	try{
		ExternalInterface.call('console.log', 'Trace: setLSOValue');
		var writeSuccess:Boolean = false;
		// Create a shared-object named &quot;userData&quot;
		var lso=SharedObject.getLocal(&quot;pd_check&quot;); 
		// Store the name
		lso.data.value=obj_value;
		var success = lso.flush();
		if (success == &quot;pending&quot;) {
		 lso.onStatus = function(result) {
		  if (result.code == &quot;SharedObject.Flush.Success&quot;) {
		   ExternalInterface.call('console.log', 'Trace: Sucess writing to disk');
		   writeSuccess = true;
		  } else {
		   ExternalInterface.call('console.log', 'Trace: Failure writing to disk');
		   writeSuccess = false;
		  }
		 };
		} else {
		 writeSuccess = success;
		}
	}
	catch(e) {
		ExternalInterface.call('console.log', 'Flash error: '+e.toString());
	}
}
</pre></p>
<p>The main thing I learned from this is, it is pretty useless as a replacement for third party cookies. This will not allow you to set cookies across domains&#8230; not that I could find anyway. So the flash movie file ( pd_check.swf ), that the flash player embed references, has to be on the same domain as the website ( where the JavaScript is trying to access the Flash ActionScript ).</p>
<p>Down the road, I am going to look into <a target="_blank" href="http://ejohn.org/blog/dom-storage/">DOM Storage</a>, mainly as a curiosity. I came across it in researching LSO&#8217;s and it looks very interesting. This facility is part of the <a target="_blank" href="http://html5.org/">HTML 5</a> spec so its not fully available yet, but it looks like a neat evolution of standard HTTP cookies.</p>
<p><strong>UPDATE:</strong> I found a way to create cross domain or third party cookies <a href="http://magp.ie/2010/10/15/javascript-library-to-manage-flash-local-stored-objects/">here</a>.</p>
<br />Filed under: <a href='http://magp.ie/category/code/'>Code</a> Tagged: <a href='http://magp.ie/tag/cookie/'>cookie</a>, <a href='http://magp.ie/tag/dom-storage/'>DOM storage</a>, <a href='http://magp.ie/tag/externalinterface/'>ExternalInterface</a>, <a href='http://magp.ie/tag/flash/'>Flash</a>, <a href='http://magp.ie/tag/javascript/'>javascript</a>, <a href='http://magp.ie/tag/local-shared-objects/'>Local Shared Objects</a>, <a href='http://magp.ie/tag/lso/'>LSO</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&amp;blog=11708208&amp;post=141&amp;subd=blogalhost&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2010/03/22/javascript-externalinterface-flash-and-local-shared-objects/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>
	</item>
	</channel>
</rss>
