<?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>SmartLogic Solutions Blog &#187; Serialization</title>
	<atom:link href="http://blog.smartlogicsolutions.com/tag/serialization/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartlogicsolutions.com</link>
	<description>News and updates from the people at SmartLogic Solutions</description>
	<lastBuildDate>Tue, 30 Nov 2010 21:39:14 +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>Migrating Serialization Changes Within an AIR Application</title>
		<link>http://blog.smartlogicsolutions.com/2008/09/11/migrating-serialization-changes-within-an-air-application/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/09/11/migrating-serialization-changes-within-an-air-application/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 06:50:07 +0000</pubDate>
		<dc:creator>Greg Jastrab</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Greg Jastrab]]></category>
		<category><![CDATA[Serialization]]></category>
		<category><![CDATA[Migration]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=255</guid>
		<description><![CDATA[I just submitted my entry to the AIR Cookbook for the AIR Cookbook Cook-off. It solves the problem of having your AIR application store an IExternalizable class on disk but then later adding more fields to that class. How would you read the old version of the class without encountering a runtime error if you [...]]]></description>
			<content:encoded><![CDATA[<p>I just submitted <a href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&#038;postid=10743&#038;loc=en_US&#038;productid=4">my entry</a> to the <a href="http://www.adobe.com/go/air_cookbook">AIR Cookbook</a> for the <a href="http://www.adobe.com/devnet/logged_in/mkoch_aircookoff.html">AIR Cookbook Cook-off</a>.</p>
<p>It solves the problem of having your AIR application store an <code>IExternalizable</code> class on disk but then later adding more fields to that class.  How would you read the old version of the class without encountering a runtime error if you tried to read the new field that wasn&#8217;t present in the older serialization?</p>
<p>Go <a href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&#038;postid=10743&#038;loc=en_US&#038;productid=4">check it out</a> the cookbook entry to find out how to do this and please rate the article!</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/10/29/i-won-the-air-cook-off/" rel="bookmark" class="crp_title">I Won the AIR Cook-off</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/11/17/migrairable-library-added-to-google-code/" rel="bookmark" class="crp_title">MigrAIRable Library Added to Google Code</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/02/25/flex-air-released-adobe/" rel="bookmark" class="crp_title">AIR 1.0 and Flex 3 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/03/31/air-linux-adobe-alpha-flexbuilder/" rel="bookmark" class="crp_title">Adobe AIR Alpha Released on Linux</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/08/27/serialization-errorbug-when-using-bytearray-readobject-iexternalizable-class/" rel="bookmark" class="crp_title">Serialization Error/Bug When Using a ByteArray and readObject in an IExternalizable Class?</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/09/11/migrating-serialization-changes-within-an-air-application/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Serialization Error/Bug When Using a ByteArray and readObject in an IExternalizable Class?</title>
		<link>http://blog.smartlogicsolutions.com/2008/08/27/serialization-errorbug-when-using-bytearray-readobject-iexternalizable-class/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/08/27/serialization-errorbug-when-using-bytearray-readobject-iexternalizable-class/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 14:21:46 +0000</pubDate>
		<dc:creator>Greg Jastrab</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Greg Jastrab]]></category>
		<category><![CDATA[Serialization]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=200</guid>
		<description><![CDATA[I&#8217;ve encountered some odd behavior that I would have expected to work when calling readObject() to de-serialize an array of anonymous objects. If anyone knows what&#8217;s going on here, please enlighten me. I&#8217;ve also filed a bug on Adobe&#8217;s bug tracking system if anyone wants to follow the progress at Adobe&#8217;s end. I&#8217;m trying to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve encountered some odd behavior that I would have expected to work when calling <code>readObject()</code> to de-serialize an array of anonymous objects.  If anyone knows what&#8217;s going on here, please enlighten me.  I&#8217;ve also <a href="http://bugs.adobe.com/jira/browse/FP-601">filed a bug</a> on Adobe&#8217;s bug tracking system if anyone wants to follow the progress at Adobe&#8217;s end.</p>
<p>I&#8217;m trying to read all of the bytes in the <code>readExternal()</code> function of a class implementing <code>IExternalizable</code>, so that I may use the <code>position</code> property to move back in stream in case I need to do so.  The problem only seems to occur if I am trying to de-serialize an Array of anonymous objects.  If I put plain old Strings in the Array it will work fine.  I find this odd since I would expect</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> readExternal<span style="color: #66cc66;">&#40;</span>input:IDataInput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> arr:<span style="color: #0066CC;">Array</span> = input.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">Array</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>to have the exact same behavior as:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> readExternal<span style="color: #66cc66;">&#40;</span>input:IDataInput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> ba:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; 
  <span style="color: #000000; font-weight: bold;">var</span> inputBytes:uint = input.<span style="color: #006600;">bytesAvailable</span>;
  input.<span style="color: #006600;">readBytes</span><span style="color: #66cc66;">&#40;</span>ba<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">var</span> baBytes:uint = ba.<span style="color: #006600;">bytesAvailable</span>;
  <span style="color: #000000; font-weight: bold;">var</span> arr:<span style="color: #0066CC;">Array</span> = ba.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">Array</span>;
  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;inputBytes == baBytes ?= &quot;</span> + <span style="color: #66cc66;">&#40;</span>inputBytes == baBytes<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// traces &quot;inputBytes == baBytes ?= true</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>AIR installer and code attached below&#8230; <span id="more-200"></span></p>
<p>The classes I&#8217;m trying to serialize are simple as I&#8217;m only trying to serialize an Array in this test application.  (Excuse the poor code of assuming the items in the Array are Objects in the <code>toString()</code function).</p>
<h4>io/WorkingSerializer.as</h4>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package io <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IExternalizable</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IDataInput</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IDataOutput</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WorkingSerializer <span style="color: #0066CC;">implements</span> IExternalizable <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> arr:<span style="color: #0066CC;">Array</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> WorkingSerializer<span style="color: #66cc66;">&#40;</span>a:<span style="color: #0066CC;">Array</span>=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			arr = a ? a : <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> readExternal<span style="color: #66cc66;">&#40;</span>input:IDataInput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			arr = input.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">Array</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> writeExternal<span style="color: #66cc66;">&#40;</span>output:IDataOutput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			output.<span style="color: #006600;">writeObject</span><span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> s:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
			<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #0066CC;">Object</span> <span style="color: #b1b100;">in</span> arr<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				s += <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>{ &quot;</span>;
				<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> p:<span style="color: #0066CC;">String</span> <span style="color: #b1b100;">in</span> obj<span style="color: #66cc66;">&#41;</span>
					s += p + <span style="color: #ff0000;">&quot;: &quot;</span> + obj<span style="color: #66cc66;">&#91;</span>p<span style="color: #66cc66;">&#93;</span> + <span style="color: #ff0000;">&quot;,&quot;</span>;
				s += <span style="color: #ff0000;">&quot; }<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;[WorkingSerializer]<span style="color: #000099; font-weight: bold;">\n</span> arr: [ &quot;</span> + s + <span style="color: #ff0000;">&quot;]&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h4>io/ProblemSerializer.as</h4>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package io <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IExternalizable</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IDataInput</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IDataOutput</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ProblemSerializer <span style="color: #0066CC;">implements</span> IExternalizable <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> arr:<span style="color: #0066CC;">Array</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ProblemSerializer<span style="color: #66cc66;">&#40;</span>a:<span style="color: #0066CC;">Array</span>=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			arr = a ? a : <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> readExternal<span style="color: #66cc66;">&#40;</span>input:IDataInput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> ba:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			input.<span style="color: #006600;">readBytes</span><span style="color: #66cc66;">&#40;</span>ba<span style="color: #66cc66;">&#41;</span>;
			arr = ba.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">Array</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> writeExternal<span style="color: #66cc66;">&#40;</span>output:IDataOutput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			output.<span style="color: #006600;">writeObject</span><span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> s:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
			<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #0066CC;">Object</span> <span style="color: #b1b100;">in</span> arr<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				s += <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>{ &quot;</span>;
				<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> p:<span style="color: #0066CC;">String</span> <span style="color: #b1b100;">in</span> obj<span style="color: #66cc66;">&#41;</span>
					s += p + <span style="color: #ff0000;">&quot;: &quot;</span> + obj<span style="color: #66cc66;">&#91;</span>p<span style="color: #66cc66;">&#93;</span> + <span style="color: #ff0000;">&quot;,&quot;</span>;
				s += <span style="color: #ff0000;">&quot; }<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;[ProblemSerializer]<span style="color: #000099; font-weight: bold;">\n</span> arr: [ &quot;</span> + s + <span style="color: #ff0000;">&quot;]&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>And here is the main application file.  I wrote it as an <a href="http://www.adobe.com/go/air">AIR</a> application so install AIR first if you don't have it.</p>
<h4>SerializationIssue.mxml</h4>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:WindowedApplication xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span>
						layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;500&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
			<span style="color: #0066CC;">import</span> io.<span style="color: #66cc66;">*</span>;
&nbsp;
			<span style="color: #0066CC;">private</span> const WORKING:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;workingfile_v1&quot;</span>;
			<span style="color: #0066CC;">private</span> const PROBLEM:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;problemfile_v1&quot;</span>;
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
				registerClassAlias<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;io.WorkingSerializer&quot;</span>, io.<span style="color: #006600;">WorkingSerializer</span><span style="color: #66cc66;">&#41;</span>;
				registerClassAlias<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;io.ProblemSerializer&quot;</span>, io.<span style="color: #006600;">ProblemSerializer</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> wo:WorkingSerializer = <span style="color: #000000; font-weight: bold;">new</span> WorkingSerializer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;some&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;items&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;are&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;here&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #000000; font-weight: bold;">var</span> s:FileStream = <span style="color: #000000; font-weight: bold;">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span>getFile<span style="color: #66cc66;">&#40;</span>WORKING<span style="color: #66cc66;">&#41;</span>, FileMode.<span style="color: #006600;">WRITE</span><span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #006600;">writeObject</span><span style="color: #66cc66;">&#40;</span>wo<span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> po:ProblemSerializer = <span style="color: #000000; font-weight: bold;">new</span> ProblemSerializer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;items&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;in&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;problem&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span>obj: <span style="color: #ff0000;">&quot;serializer&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span>getFile<span style="color: #66cc66;">&#40;</span>PROBLEM<span style="color: #66cc66;">&#41;</span>, FileMode.<span style="color: #006600;">WRITE</span><span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #006600;">writeObject</span><span style="color: #66cc66;">&#40;</span>po<span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getFile<span style="color: #66cc66;">&#40;</span>filename:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:File <span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span> File.<span style="color: #006600;">applicationStorageDirectory</span>.<span style="color: #006600;">resolvePath</span><span style="color: #66cc66;">&#40;</span>filename<span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> readObj<span style="color: #66cc66;">&#40;</span>readWorking:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> s:FileStream = <span style="color: #000000; font-weight: bold;">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span>getFile<span style="color: #66cc66;">&#40;</span>readWorking ? WORKING : PROBLEM<span style="color: #66cc66;">&#41;</span>, FileMode.<span style="color: #006600;">READ</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>readWorking<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">var</span> wo:WorkingSerializer = s.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as WorkingSerializer;
					logger.<span style="color: #0066CC;">text</span> += wo + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
					<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>wo<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
				<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">var</span> po:ProblemSerializer = s.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as ProblemSerializer;
					logger.<span style="color: #0066CC;">text</span> += po + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
					<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>po<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
				s.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:HBox<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Read Working Serializer&quot;</span> click=<span style="color: #ff0000;">&quot;readObj(true)&quot;</span> <span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Read Problem Serializer&quot;</span> click=<span style="color: #ff0000;">&quot;readObj()&quot;</span> <span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:HBox<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:Panel title=<span style="color: #ff0000;">&quot;Logging&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:TextArea id=<span style="color: #ff0000;">&quot;logger&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> editable=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #0066CC;">wordWrap</span>=<span style="color: #ff0000;">&quot;true&quot;</span>
					 updateComplete=<span style="color: #ff0000;">&quot;logger.verticalScrollPosition=logger.maxVerticalScrollPosition&quot;</span> <span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Panel<span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #66cc66;">&lt;/</span>mx:WindowedApplication<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>To test this out without having to compile it yourself, I've compiled it as an AIR installer: <a href='http://blog.smartlogicsolutions.com/wp-content/uploads/2008/08/serializationissue.air'>Serialization Issue AIR Application</a>.  And the source: <a href='http://blog.smartlogicsolutions.com/wp-content/uploads/2008/08/serializationissue.zip'>Serialization Issue Source</a>.</p>
<p>When I run the code below and click on the "Read Working Serializer" button I correctly see:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>WorkingSerializer<span style="color: #66cc66;">&#93;</span>
 arr: <span style="color: #66cc66;">&#91;</span> 
	<span style="color: #66cc66;">&#123;</span> obj: some, <span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#123;</span> obj: items, <span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#123;</span> obj: are, <span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#123;</span> obj: here, <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#93;</span></pre></div></div>

<p>get output to the console.  But, if I click on the "Read Problem Serializer" button I get the following RangeError:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">RangeError: <span style="color: #0066CC;">Error</span> <span style="color: #808080; font-style: italic;">#2006: The supplied index is out of bounds. </span>
at flash.<span style="color: #006600;">utils</span>::ByteArray<span style="color: #66cc66;">/</span>readObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> 
at io::ProblemSerializer<span style="color: #66cc66;">/</span>readExternal<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&lt;</span>path to environment<span style="color: #66cc66;">&gt;/</span>SerializationIssue<span style="color: #66cc66;">/</span>src<span style="color: #66cc66;">/</span>io<span style="color: #66cc66;">/</span>ProblemSerializer.<span style="color: #006600;">as</span>:<span style="color: #cc66cc;">19</span><span style="color: #66cc66;">&#93;</span> 
at flash.<span style="color: #006600;">filesystem</span>::FileStream<span style="color: #66cc66;">/</span>readObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> 
at SerializationIssue<span style="color: #66cc66;">/</span>readObj<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&lt;</span>path to environment<span style="color: #66cc66;">&gt;/</span>SerializationIssue<span style="color: #66cc66;">/</span>src<span style="color: #66cc66;">/</span>SerializationIssue.<span style="color: #006600;">mxml</span>:<span style="color: #cc66cc;">40</span><span style="color: #66cc66;">&#93;</span> 
at SerializationIssue<span style="color: #66cc66;">/</span>___SerializationIssue_Button2_click<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&lt;</span>path to environment<span style="color: #66cc66;">&gt;/</span>SerializationIssue<span style="color: #66cc66;">/</span>src<span style="color: #66cc66;">/</span>SerializationIssue.<span style="color: #006600;">mxml</span>:<span style="color: #cc66cc;">51</span><span style="color: #66cc66;">&#93;</span></pre></div></div>

<p>In the meantime I'll find a workaround for this, but has anyone encountered anything similar to this or know why this isn't working?</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/07/16/creating-custom-layout-in-flex-4-gumbo/" rel="bookmark" class="crp_title">Creating a Custom Layout Class in Flex 4</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/11/losing-data-drag-and-drop-custom-class-flex-serialization/" rel="bookmark" class="crp_title">Losing Data When Drag and Dropping Custom Classes in Flex?</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/19/creating-custom-flex-4-skinnable-component/" rel="bookmark" class="crp_title">Creating Your First Custom SkinnableComponent in Flex 4</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/05/28/flex-4-login-form-component/" rel="bookmark" class="crp_title">Flex 4 Login Form Component</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/08/16/recreating-elys-flex-4-list-component-series/" rel="bookmark" class="crp_title">Recreating Ely&#8217;s Flex 4 List Component Series</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/08/27/serialization-errorbug-when-using-bytearray-readobject-iexternalizable-class/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

