<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Serializing display objects</title>
	<atom:link href="http://jacwright.com/blog/201/serializing-display-objects/feed/" rel="self" type="application/rss+xml" />
	<link>http://jacwright.com/blog/201/serializing-display-objects/</link>
	<description>Flex, AIR, PHP, etc.</description>
	<lastBuildDate>Thu, 29 Jul 2010 18:05:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Nimesh Nanda</title>
		<link>http://jacwright.com/blog/201/serializing-display-objects/comment-page-1/#comment-9140</link>
		<dc:creator>Nimesh Nanda</dc:creator>
		<pubDate>Mon, 29 Mar 2010 12:19:13 +0000</pubDate>
		<guid isPermaLink="false">http://jacwright.com/blog/?p=201#comment-9140</guid>
		<description>Hi, 
   These are very nice example but i need a source code above example.....</description>
		<content:encoded><![CDATA[<p>Hi,<br />
   These are very nice example but i need a source code above example&#8230;..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan</title>
		<link>http://jacwright.com/blog/201/serializing-display-objects/comment-page-1/#comment-8457</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Tue, 18 Aug 2009 09:42:24 +0000</pubDate>
		<guid isPermaLink="false">http://jacwright.com/blog/?p=201#comment-8457</guid>
		<description>Yes the size with b64 is bigger .. but the bytearray gets compressed, so it&#039;s not so big.

bests
alan</description>
		<content:encoded><![CDATA[<p>Yes the size with b64 is bigger .. but the bytearray gets compressed, so it&#8217;s not so big.</p>
<p>bests<br />
alan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Wright</title>
		<link>http://jacwright.com/blog/201/serializing-display-objects/comment-page-1/#comment-8453</link>
		<dc:creator>Jacob Wright</dc:creator>
		<pubDate>Mon, 17 Aug 2009 22:19:08 +0000</pubDate>
		<guid isPermaLink="false">http://jacwright.com/blog/?p=201#comment-8453</guid>
		<description>When working with ByteArrays I&#039;ve always gotten the EoF error because I didn&#039;t specify how much to read. In readExternal you could try input.readBytes(byteArray, byteArray.bytesAvailable); or something similar. I&#039;m sorry I don&#039;t have time to test it out right now but I personally would try to go without base64ing it as that makes it bigger. But if it works and you&#039;re ok with the size, great!</description>
		<content:encoded><![CDATA[<p>When working with ByteArrays I&#8217;ve always gotten the EoF error because I didn&#8217;t specify how much to read. In readExternal you could try input.readBytes(byteArray, byteArray.bytesAvailable); or something similar. I&#8217;m sorry I don&#8217;t have time to test it out right now but I personally would try to go without base64ing it as that makes it bigger. But if it works and you&#8217;re ok with the size, great!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan</title>
		<link>http://jacwright.com/blog/201/serializing-display-objects/comment-page-1/#comment-8451</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Mon, 17 Aug 2009 12:24:43 +0000</pubDate>
		<guid isPermaLink="false">http://jacwright.com/blog/?p=201#comment-8451</guid>
		<description>Hi .. again big thanks for Your help.
Writing raw pixel data reulted in EoF error, so i compresed that bytearray and converted it to Base64 string. When reading i just converted it back and uncompressed 

it looks like this

        import flash.display.*;
	import flash.utils.ByteArray;
	import flash.utils.IExternalizable;
	import flash.utils.IDataInput;
	import flash.utils.IDataOutput;
	import flash.geom.Rectangle;
	import flash.net.registerClassAlias;
	import com.dynamicflash.util.Base64;

	public class LayerBitmap extends Bitmap implements IExternalizable {
		
		public function LayerBitmap() {
			// ..
		}

		public function writeExternal(output:IDataOutput):void {
			output.writeObject(this.transform.matrix);
			output.writeInt(bitmapData.width);
			output.writeInt(bitmapData.height);
			var bytes:ByteArray = bitmapData.getPixels(new Rectangle(0,0,bitmapData.width,bitmapData.height));
			bytes.compress();
			output.writeUTF(Base64.encodeByteArray(bytes));
		}

		public function readExternal(input:IDataInput):void {
			transform.matrix=input.readObject();
			this.bitmapData=new BitmapData(input.readInt(),input.readInt(),true,0);
			var bytes:ByteArray = Base64.decodeToByteArray(input.readUTF());
			bytes.uncompress();
			bitmapData.setPixels(new Rectangle(0, 0, bitmapData.width, bitmapData.height), bytes);
		}
	}

thnaks again
alan</description>
		<content:encoded><![CDATA[<p>Hi .. again big thanks for Your help.<br />
Writing raw pixel data reulted in EoF error, so i compresed that bytearray and converted it to Base64 string. When reading i just converted it back and uncompressed </p>
<p>it looks like this</p>
<p>        import flash.display.*;<br />
	import flash.utils.ByteArray;<br />
	import flash.utils.IExternalizable;<br />
	import flash.utils.IDataInput;<br />
	import flash.utils.IDataOutput;<br />
	import flash.geom.Rectangle;<br />
	import flash.net.registerClassAlias;<br />
	import com.dynamicflash.util.Base64;</p>
<p>	public class LayerBitmap extends Bitmap implements IExternalizable {</p>
<p>		public function LayerBitmap() {<br />
			// ..<br />
		}</p>
<p>		public function writeExternal(output:IDataOutput):void {<br />
			output.writeObject(this.transform.matrix);<br />
			output.writeInt(bitmapData.width);<br />
			output.writeInt(bitmapData.height);<br />
			var bytes:ByteArray = bitmapData.getPixels(new Rectangle(0,0,bitmapData.width,bitmapData.height));<br />
			bytes.compress();<br />
			output.writeUTF(Base64.encodeByteArray(bytes));<br />
		}</p>
<p>		public function readExternal(input:IDataInput):void {<br />
			transform.matrix=input.readObject();<br />
			this.bitmapData=new BitmapData(input.readInt(),input.readInt(),true,0);<br />
			var bytes:ByteArray = Base64.decodeToByteArray(input.readUTF());<br />
			bytes.uncompress();<br />
			bitmapData.setPixels(new Rectangle(0, 0, bitmapData.width, bitmapData.height), bytes);<br />
		}<br />
	}</p>
<p>thnaks again<br />
alan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Wright</title>
		<link>http://jacwright.com/blog/201/serializing-display-objects/comment-page-1/#comment-8446</link>
		<dc:creator>Jacob Wright</dc:creator>
		<pubDate>Wed, 12 Aug 2009 15:34:26 +0000</pubDate>
		<guid isPermaLink="false">http://jacwright.com/blog/?p=201#comment-8446</guid>
		<description>Another way to handle serialization is using the IExternalizable interface. If you implement it, the two methods you use to implement it allow you to control exactly what is written when serialized. I did some bitmap serialization with something like the following (note, this hasn&#039;t been tested, it is an example of something like what I did):

&lt;div style=&quot;position:relative;height:440px;margin:0;background:none;&quot;&gt;
&lt;pre style=&quot;position:absolute;left:-10px;top:-20px;right:0;&quot;&gt;
public class MyBitmap extends Bitmap implements IExternalizable
{
	public function writeExternal(output:IDataOutput):void
	{
		output.writeObject(transform.matrix); // takes care of x, y, rotation, etc.
		output.writeInt(bitmapData.width);
		output.writeInt(bitmapData.height);
		var byteArray:ByteArray = bitmapData.getPixels(new Rectangle(0, 0, bitmapData.width, bitmapData.height));
		output.writeBytes(byteArray);
	}
	
	public function readExternal(input:IDataInput):void
	{
		transform.matrix = input.readObject();
		var width:int = input.readInt();
		var height:int = input.readInt();
		bitmapData = new BitmapData(width, height, true, 0);
		
		var byteArray:ByteArray = new ByteArray();
		input.readBytes(byteArray);
		bitmapData.setPixels(new Rectangle(0, 0, width, height), byteArray);
	}
}
&lt;/pre&gt;
&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>Another way to handle serialization is using the IExternalizable interface. If you implement it, the two methods you use to implement it allow you to control exactly what is written when serialized. I did some bitmap serialization with something like the following (note, this hasn&#8217;t been tested, it is an example of something like what I did):</p>
<div style="position:relative;height:440px;margin:0;background:none;">
<pre style="position:absolute;left:-10px;top:-20px;right:0;">
public class MyBitmap extends Bitmap implements IExternalizable
{
	public function writeExternal(output:IDataOutput):void
	{
		output.writeObject(transform.matrix); // takes care of x, y, rotation, etc.
		output.writeInt(bitmapData.width);
		output.writeInt(bitmapData.height);
		var byteArray:ByteArray = bitmapData.getPixels(new Rectangle(0, 0, bitmapData.width, bitmapData.height));
		output.writeBytes(byteArray);
	}

	public function readExternal(input:IDataInput):void
	{
		transform.matrix = input.readObject();
		var width:int = input.readInt();
		var height:int = input.readInt();
		bitmapData = new BitmapData(width, height, true, 0);

		var byteArray:ByteArray = new ByteArray();
		input.readBytes(byteArray);
		bitmapData.setPixels(new Rectangle(0, 0, width, height), byteArray);
	}
}
</pre>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan</title>
		<link>http://jacwright.com/blog/201/serializing-display-objects/comment-page-1/#comment-8445</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Wed, 12 Aug 2009 14:02:13 +0000</pubDate>
		<guid isPermaLink="false">http://jacwright.com/blog/?p=201#comment-8445</guid>
		<description>hi .. first of all big thanks .. i&#039;ve managed to serialize sprites .. now i&#039;m standing before much larger problem .. i&#039;m trying to serialize a sprite containing bitmap ..

i have overrided bitmapdata class so it can be serialized (the same way as you did with transform class) .. i wanted to try making something like this -
when creating my bitmapdata object i want to save base64 encoded bitmap in a public property (inside my bitmapdata instance) as string and then, when cloned bring it back .. 

so i was thinking .. or better .. asking if you know if there is a trick that will (internaly) automaticly (when cloned) check for that string and bring my bitmap back

bests
alan</description>
		<content:encoded><![CDATA[<p>hi .. first of all big thanks .. i&#8217;ve managed to serialize sprites .. now i&#8217;m standing before much larger problem .. i&#8217;m trying to serialize a sprite containing bitmap ..</p>
<p>i have overrided bitmapdata class so it can be serialized (the same way as you did with transform class) .. i wanted to try making something like this -<br />
when creating my bitmapdata object i want to save base64 encoded bitmap in a public property (inside my bitmapdata instance) as string and then, when cloned bring it back .. </p>
<p>so i was thinking .. or better .. asking if you know if there is a trick that will (internaly) automaticly (when cloned) check for that string and bring my bitmap back</p>
<p>bests<br />
alan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Wright</title>
		<link>http://jacwright.com/blog/201/serializing-display-objects/comment-page-1/#comment-8441</link>
		<dc:creator>Jacob Wright</dc:creator>
		<pubDate>Thu, 06 Aug 2009 20:13:57 +0000</pubDate>
		<guid isPermaLink="false">http://jacwright.com/blog/?p=201#comment-8441</guid>
		<description>Alan: Be sure to register all the aliases as stated in the example. And an extra tidbit: I found you can even register two classes to the same alias and they&#039;ll both write out with that alias but when they come back out of the bytearray they are set to the last registered class. So you can serialize Sprites and have them come back out as MySprites.

e.g.

registerClassAlias(&quot;Sprite&quot;, Sprite);
registerClassAlias(&quot;Sprite&quot;, MySprite);
registerClassAlias(&quot;Transform&quot;, Transform);
registerClassAlias(&quot;Transform&quot;, MyTransform);

And of course, don&#039;t forget to register the other stuff too.</description>
		<content:encoded><![CDATA[<p>Alan: Be sure to register all the aliases as stated in the example. And an extra tidbit: I found you can even register two classes to the same alias and they&#8217;ll both write out with that alias but when they come back out of the bytearray they are set to the last registered class. So you can serialize Sprites and have them come back out as MySprites.</p>
<p>e.g.</p>
<p>registerClassAlias(&#8220;Sprite&#8221;, Sprite);<br />
registerClassAlias(&#8220;Sprite&#8221;, MySprite);<br />
registerClassAlias(&#8220;Transform&#8221;, Transform);<br />
registerClassAlias(&#8220;Transform&#8221;, MyTransform);</p>
<p>And of course, don&#8217;t forget to register the other stuff too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan</title>
		<link>http://jacwright.com/blog/201/serializing-display-objects/comment-page-1/#comment-8440</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Thu, 06 Aug 2009 16:11:31 +0000</pubDate>
		<guid isPermaLink="false">http://jacwright.com/blog/?p=201#comment-8440</guid>
		<description>Hi .. i have problems with serializing ..
i&#039;ve wrote my class extending sprite and overrided Transform class .. but when i load a serialized instance of my class , i still get an argument count mismatch error .. do i have to override all geom classes?

all the best
alan</description>
		<content:encoded><![CDATA[<p>Hi .. i have problems with serializing ..<br />
i&#8217;ve wrote my class extending sprite and overrided Transform class .. but when i load a serialized instance of my class , i still get an argument count mismatch error .. do i have to override all geom classes?</p>
<p>all the best<br />
alan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Wright</title>
		<link>http://jacwright.com/blog/201/serializing-display-objects/comment-page-1/#comment-8330</link>
		<dc:creator>Jacob Wright</dc:creator>
		<pubDate>Fri, 01 May 2009 22:14:03 +0000</pubDate>
		<guid isPermaLink="false">http://jacwright.com/blog/?p=201#comment-8330</guid>
		<description>Make sure you are getting all the registerClassAlias&#039;s and that you are at the beginning of your bytearray (ba.position = 0)

If you&#039;re following the code I have above and its still not working let me know, but it should work in Flash 9, flex or flash CS3.</description>
		<content:encoded><![CDATA[<p>Make sure you are getting all the registerClassAlias&#8217;s and that you are at the beginning of your bytearray (ba.position = 0)</p>
<p>If you&#8217;re following the code I have above and its still not working let me know, but it should work in Flash 9, flex or flash CS3.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: person</title>
		<link>http://jacwright.com/blog/201/serializing-display-objects/comment-page-1/#comment-8329</link>
		<dc:creator>person</dc:creator>
		<pubDate>Fri, 01 May 2009 18:21:12 +0000</pubDate>
		<guid isPermaLink="false">http://jacwright.com/blog/?p=201#comment-8329</guid>
		<description>Is this technique exclusive to Flash Player 10 or to Flex?  I&#039;m trying this in Flash CS3/FP 9 and coming up empty.  byteArray.readObject() returns null.</description>
		<content:encoded><![CDATA[<p>Is this technique exclusive to Flash Player 10 or to Flex?  I&#8217;m trying this in Flash CS3/FP 9 and coming up empty.  byteArray.readObject() returns null.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
