<?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>D2Coding &#187; Actionscript</title>
	<atom:link href="http://www.D2Coding.com/tag/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.D2Coding.com</link>
	<description></description>
	<lastBuildDate>Sun, 23 May 2010 03:06:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Actionscript Locally Persistent Data Object</title>
		<link>http://www.D2Coding.com/2009/05/30/actionscript-locally-persistent-data-object/</link>
		<comments>http://www.D2Coding.com/2009/05/30/actionscript-locally-persistent-data-object/#comments</comments>
		<pubDate>Sat, 30 May 2009 18:09:28 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[SharedObject]]></category>

		<guid isPermaLink="false">http://www.D2Coding.com/?p=25</guid>
		<description><![CDATA[Flash has an easy way to save locally persistent data directly from Actionscript. Using the SharedObject Class, one can define many data points within the same object and use them like you would &#8220;cookies&#8221;.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Declare a cookie name
var cookieName:String = &#34;cookieExample&#34;;
&#160;
//Create an object to store cookie data
var cookie:SharedObject = SharedObject.getLocal&#40;cookieName&#41;;
&#160;
//If the data we are looking for doesn't exist (and it truly doesn't exist, it's just not 0)
if&#40;!cookie.data.firstPageToShow &#38;&#38; cookie.data.firstPageToShow!=0&#41;&#123;
&#160;
	//initiate the data point
	cookie.data.firstPageToShow = 0;
&#160;
&#125;else&#123;
&#160;
	//increment the data point
	cookie.data.firstPageToShow += 1;
&#125;

After this code runs, if the user has visited the site before, they ...]]></description>
			<content:encoded><![CDATA[<p>Flash has an easy way to save locally persistent data directly from Actionscript. Using the SharedObject Class, one can define many data points within the same object and use them like you would &#8220;cookies&#8221;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//Declare a cookie name</span>
<span style="color: #000000; font-weight: bold;">var</span> cookieName:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;cookieExample&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//Create an object to store cookie data</span>
<span style="color: #000000; font-weight: bold;">var</span> cookie:<span style="color: #0066CC;">SharedObject</span> = <span style="color: #0066CC;">SharedObject</span>.<span style="color: #0066CC;">getLocal</span><span style="color: #66cc66;">&#40;</span>cookieName<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//If the data we are looking for doesn't exist (and it truly doesn't exist, it's just not 0)</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>cookie.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">firstPageToShow</span> <span style="color: #66cc66;">&amp;&amp;</span> cookie.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">firstPageToShow</span><span style="color: #66cc66;">!</span>=<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">//initiate the data point</span>
	cookie.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">firstPageToShow</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">//increment the data point</span>
	cookie.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">firstPageToShow</span> += <span style="color: #cc66cc;">1</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>After this code runs, if the user has visited the site before, they will be taken to the page after they last left, or if they haven&#8217;t visited the site yet, the user will be taken to the 0th page.</p>
<p>In the real world, this code has been used to ensure that users visiting a site with a rotating campaign, saw each image and caption of the campaign on subsequent visits.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.D2Coding.com/2009/05/30/actionscript-locally-persistent-data-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
