<?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; DOM storage</title>
	<atom:link href="http://magp.ie/tag/dom-storage/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>Wed, 16 May 2012 09:40:29 +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; DOM storage</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, 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&#038;blog=11708208&#038;post=141&#038;subd=blogalhost&#038;ref=&#038;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&#038;blog=11708208&#038;post=141&#038;subd=blogalhost&#038;ref=&#038;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>
