<?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"
	>

<channel>
	<title>blok.krisrok.de</title>
	<atom:link href="http://krisrok.de/blok/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://krisrok.de/blok</link>
	<description>flash, actionscript, pixel bender and blah.. you know the drill</description>
	<pubDate>Tue, 02 Jun 2009 13:51:57 +0000</pubDate>
	
	<language>en</language>
			<item>
		<title>IconUtilityPlus - use DisplayObjects as flex icons</title>
		<link>http://krisrok.de/blok/?p=70</link>
		<comments>http://krisrok.de/blok/?p=70#comments</comments>
		<pubDate>Fri, 15 May 2009 11:33:03 +0000</pubDate>
		<dc:creator>kris</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://krisrok.de/blok/?p=70</guid>
		<description><![CDATA[recently i needed a way to generate small preview-thumbs and put them on flex' Buttons - as it turned out, it isn't that easy to use dynamic content as icons at all.
after some while i found a nice way to put dynamically loaded images in icons: ben stucki's IconUtility.
i took his class and kicked it [...]]]></description>
			<content:encoded><![CDATA[<p>recently i needed a way to generate small preview-thumbs and put them on flex' Buttons - as it turned out, it isn't that easy to use dynamic content as icons at all.<br />
after some while i found a nice way to put dynamically loaded images in icons: ben stucki's <a href="http://blog.benstucki.net/?p=42">IconUtility</a>.</p>
<p>i took his class and kicked it up a notch. now it's able to take any DisplayObject as a source and lets you use it as an icon for flex components:</p>
<div class="igBar"><span id="lactionscript-3"><a href="#" onclick="javascript:showPlainTxt('actionscript-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-3">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> sprite:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sprite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xff0000, <span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">5</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sprite.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawCircle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #cc66cc;color:#800000;">15</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">button</span>:<span style="color: #0066CC;">Button</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">button</span>.<span style="color: #0066CC;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"icon"</span>, IconUtilityPlus.<span style="color: #006600;">getClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">button</span>, sprite<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>of course it works in MXML, too:</p>
<div class="igBar"><span id="lactionscript-4"><a href="#" onclick="javascript:showPlainTxt('actionscript-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-4">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;mx:<span style="color: #0066CC;">Button</span> id=<span style="color: #ff0000;">"button"</span> icon=<span style="color: #ff0000;">"{IconUtilityPlus.getClass(button, sprite)}"</span>/&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>i've also added a third parameter for animated DisplayObjects like Video or MovieClip - added this just for fun, it will definitely cost some performance to display animated stuff and may be buggy.</p>
<p>thanks again to ben for the previous work, it really is some smart way to bypass adobe's way of only using classes <img src='http://krisrok.de/_blok/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>here it is: <a href="http://krisrok.de/flash/classes/de/kris/utils/flex/IconUtilityPlus.as">IconUtilityPlus.as</a></p>
<p><strong>edit</strong>: fixed drawing method for DisplayObjects with offsets <0</p>
]]></content:encoded>
			<wfw:commentRss>http://krisrok.de/blok/?feed=rss2&amp;p=70</wfw:commentRss>
		</item>
		<item>
		<title>communicaty arbitrary data via rtfmp (late sources)</title>
		<link>http://krisrok.de/blok/?p=67</link>
		<comments>http://krisrok.de/blok/?p=67#comments</comments>
		<pubDate>Mon, 11 May 2009 13:37:15 +0000</pubDate>
		<dc:creator>kris</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://krisrok.de/blok/?p=67</guid>
		<description><![CDATA[here are the sources. just for the sakes of a new blog post..  
i wish i had the time to play around with it some more by now - months have passed! :/
remember to get a status account and put your id in the sources - otherwise it won't work. have fun.
]]></description>
			<content:encoded><![CDATA[<p>here are the <a href="http://krisrok.de/flash/projects/stratus.zip">sources</a>. just for the sakes of a new blog post.. <img src='http://krisrok.de/_blok/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>i wish i had the time to play around with it some more by now - months have passed! :/</p>
<p>remember to get a status account and put your id in the sources - otherwise it won't work. have fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://krisrok.de/blok/?feed=rss2&amp;p=67</wfw:commentRss>
		</item>
		<item>
		<title>communicating arbitrary data via rtfmp (pt. 2)</title>
		<link>http://krisrok.de/blok/?p=57</link>
		<comments>http://krisrok.de/blok/?p=57#comments</comments>
		<pubDate>Mon, 19 Jan 2009 20:24:02 +0000</pubDate>
		<dc:creator>kris</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

		<category><![CDATA[Networking]]></category>

		<guid isPermaLink="false">http://krisrok.de/blok/?p=57</guid>
		<description><![CDATA[sending custom classes via rtmfp? well, let's try  
according to the example of the first part of this article we would now like to pass our receiverFunction() an instance of SomeObject instead of a String.

setup
here's the initial class SomeObject which we'll try to send from one peer to another:
PLAIN TEXT
Actionscript:




package&#160; 


&#123;


&#160; &#160; public class [...]]]></description>
			<content:encoded><![CDATA[<p>sending custom classes via rtmfp? well, let's try <img src='http://krisrok.de/_blok/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>according to the example of the <a href="http://krisrok.de/blok/?p=53">first part of this article</a> we would now like to pass our receiverFunction() an instance of SomeObject instead of a String.</p>
<p></b><br />
<strong>setup</strong></p>
<p>here's the initial class SomeObject which we'll try to send from one peer to another:</p>
<div class="igBar"><span id="lactionscript-15"><a href="#" onclick="javascript:showPlainTxt('actionscript-15'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-15">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">package&nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SomeObject</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SomeObject<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = value;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> value<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span> i; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>of course we have to adjust our peers as well:</p>
<p>sending peer:</p>
<div class="igBar"><span id="lactionscript-16"><a href="#" onclick="javascript:showPlainTxt('actionscript-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-16">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">netStream</span>:<span style="color: #0066CC;">NetStream</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">NetStream</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">netConnection</span>, <span style="color: #0066CC;">NetStream</span>.<span style="color: #006600;">DIRECT_CONNECTIONS</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> sendTimer:Timer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">1000</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sendTimer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>, senderFunction<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">...</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> senderFunction<span style="color: #66cc66;">&#40;</span>te:TimerEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> someObject:SomeObject = <span style="color: #000000; font-weight: bold;">new</span> SomeObject<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>*<span style="color: #cc66cc;color:#800000;">303</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">netStream</span>.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span>”receiverFunction”, someObject<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
<em>the timer-function sends an instance of SomeObject with a random value every second through the stream.</em></p>
<p>receiving peer:</p>
<div class="igBar"><span id="lactionscript-17"><a href="#" onclick="javascript:showPlainTxt('actionscript-17'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-17">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">netStream</span>:<span style="color: #0066CC;">NetStream</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">NetStream</span><span style="color: #66cc66;">&#40;</span>nc, id_of_sending_peer<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> clientObj:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">clientObj.<span style="color: #006600;">receiverFunction</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>arg1:SomeObject<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>arg1.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">netStream</span>.<span style="color: #006600;">client</span> = clientObj; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
<em>we want the receiver to accept the object and trace its value in the console.</em></p>
<p>unfortunately the application in its current state would throw an AsyncErrorEvent caused by the fact that the receiver is not able to read a SomeObject from the stream, it only sees a strange Object of unknown type:<br />
<code>Type Coercion failed: cannot convert Object@3019da9 to SomeObject.</code></p>
<p>maybe you know this error from experiments with ByteArray. in fact there is quite a sum of analogies between the ByteArray-methods writeObject() and readObject() and the exchange of data via NetStream.send() - that's because both are data streams.<br />
so we have to make our SomeObject serializable, means: if we can write it to a ByteArray and read back again, we're halfway there. </p>
<p>i think i'll put a jump here, because this may be getting a longer article <img src='http://krisrok.de/_blok/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<span id="more-57"></span></p>
<p></b><br />
<strong>serialize it</strong></p>
<p>first of all our class has to implement the interface <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/IExternalizable.html">IExternalizable</a>, the language reference tells us why:</p>
<blockquote><p>The IExternalizable interface provides control over serialization of a class as it is encoded into a data stream. The writeExternal() and readExternal() methods of the IExternalizable interface are implemented by a class to allow customization of the contents and format of the data stream (but not the classname or type) for an object and its supertypes. Each individual class must serialize and reconstruct the state of its instances. </p></blockquote>
<p>so we have to find a way to break our SomeObject down to its pieces. fortunately the load of our class is only one integer, so the readExternal() and writeExternal() implementations would look something like this:</p>
<div class="igBar"><span id="lactionscript-18"><a href="#" onclick="javascript:showPlainTxt('actionscript-18'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-18">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; i = input.<span style="color: #006600;">readInt</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; output.<span style="color: #006600;">writeInt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>when an instance of SomeObject is written to a data stream, it "manually" writes the load, i, to the output-stream.<br />
and when you try to read the instance from an input-stream, it "manually" reconstructs the object by creating a blank object and filling it with the load.<br />
(those streams i'm talking about can be one of the following: ByteArray, LocalConnection, SharedObject, NetConnection and in our case NetStream!)</p>
<p>note! this blank object is an instance created with no parameters, like <code>new SomeObject()</code>, that is why we have to put a standard-constructor in place of the one expecting the value parameter:</p>
<div class="igBar"><span id="lactionscript-19"><a href="#" onclick="javascript:showPlainTxt('actionscript-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-19">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SomeObject<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; i = value;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>so that's it? ha! of course not. i think adobe should really add this piece of information to the api of IExternalizable, because without it the readExternal() and writeExternal() methods are nice and all - but the serialization just won't work.<br />
we need to register the class for AMF encoding (which i called 'serialization' until now and from here on again), the flash.net package supplies the function for that: <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/package.html#registerClassAlias()">registerClassAlias()</a>!</p>
<p>a nifty way to do this for our class is with a static constant. with a static constant we can have the function call to registerCallAlias() only once for all our instances, even though it returns nothing:</p>
<div class="igBar"><span id="lactionscript-20"><a href="#" onclick="javascript:showPlainTxt('actionscript-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-20">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const ALIAS:* = registerClassAlias<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">"SomeObject"</span>, SomeObject <span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>ok, now we're nearly set. our class is now ready to be written to and read from a data stream, e.g. ByteArray:</p>
<div class="igBar"><span id="lactionscript-21"><a href="#" onclick="javascript:showPlainTxt('actionscript-21'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-21">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> someObject:SomeObject = <span style="color: #000000; font-weight: bold;">new</span> SomeObject<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">303</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> byteArray:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">byteArray.<span style="color: #006600;">writeObject</span><span style="color: #66cc66;">&#40;</span>someObject<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">byteArray.<span style="color: #0066CC;">position</span> = <span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> someClone:SomeObject = byteArray.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>someClone.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//outputs 303 </span></div>
</li>
</ol>
</div>
</div>
</div>
<p>
<em>this is a good and fast way to test if the serialization and reconstruction of your class works without taking the long route through the internet and back again via NetStream <img src='http://krisrok.de/_blok/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </em></p>
<p></b><br />
<strong>stupidity</strong></p>
<p>the local serialization works. the remote however does NOT:<br />
<code>ArgumentError: Error #2173: Unable to read object in stream.  The class SomeObject does not implement flash.utils.IExternalizable but is aliased to an externalizable class.</code></p>
<p>why? i dont really know the answer (maybe you do?), but i know the solution:<br />
we have to (trash-)instantiate the class once on the receiver's side. on the receiving NetStream's client-object to be exactly.</p>
<p>what? yeah right. here is the way how to do this for our clientObj we used above:</p>
<div class="igBar"><span id="lactionscript-22"><a href="#" onclick="javascript:showPlainTxt('actionscript-22'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-22">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">clientObj = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">clientObj.<span style="color: #006600;">nonsense</span> = <span style="color: #000000; font-weight: bold;">new</span> SomeObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">clientObj.<span style="color: #006600;">nonsense</span> = <span style="color: #000000; font-weight: bold;">null</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">clientObj.<span style="color: #006600;">receiverFunction</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>arg1:SomeObject<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>arg1.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">netStream</span>.<span style="color: #006600;">client</span> = clientObj; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>you could also write a new class and use it as the NetStream's client-object:</p>
<div class="igBar"><span id="lactionscript-23"><a href="#" onclick="javascript:showPlainTxt('actionscript-23'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-23">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">package&nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">import</span> SomeObject;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ReceiverClient </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ReceiverClient<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> SomeObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> receiverFunction<span style="color: #66cc66;">&#40;</span>so:SomeObject<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>so.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>and finally, DONE! now the peers can exchange instances of SomeObject without any strange errors.</p>
<p>here's the now complete and working SomeObject-implementation:</p>
<div class="igBar"><span id="lactionscript-24"><a href="#" onclick="javascript:showPlainTxt('actionscript-24'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-24">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">package&nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">registerClassAlias</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IDataInput</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IDataOutput</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">IExternalizable</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SomeObject <span style="color: #0066CC;">implements</span> IExternalizable</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const ALIAS:* = registerClassAlias<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">"SomeObject"</span>, SomeObject <span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SomeObject<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = value;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> value<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span> i; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &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></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = input.<span style="color: #006600;">readInt</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &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></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.<span style="color: #006600;">writeInt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p></b><br />
<strong>conclusion</strong></p>
<p>i know it sounds like a lot to do, but essentially you just have to:</p>
<ul>
<li>implement IExternalizable</li>
<li>register the class for serialization with registerClassAlias()</li>
<li>instantiate the class on the receiver's client once</li>
</ul>
<p>just remember always to break everything down to serializable types and provide a way to put it back together again.</p>
<p></b><br />
i hope you guys come up with some cool ways to use this! <img src='http://krisrok.de/_blok/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://krisrok.de/blok/?feed=rss2&amp;p=57</wfw:commentRss>
		</item>
		<item>
		<title>communicating arbitrary data via rtfmp (pt. 1)</title>
		<link>http://krisrok.de/blok/?p=53</link>
		<comments>http://krisrok.de/blok/?p=53#comments</comments>
		<pubDate>Wed, 07 Jan 2009 15:37:15 +0000</pubDate>
		<dc:creator>kris</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

		<category><![CDATA[Networking]]></category>

		<guid isPermaLink="false">http://krisrok.de/blok/?p=53</guid>
		<description><![CDATA[hi there and a happy new one (can you still say that on january 7th?).
since i am supposed to work on my bachelor thesis it got quiet around here.
but when i read about the new stratus service a few days ago i couldn't wait to get my hands on it. for those who haven't heard [...]]]></description>
			<content:encoded><![CDATA[<p>hi there and a happy new one (can you still say that on january 7th?).</p>
<p>since i am supposed to work on my bachelor thesis it got quiet around here.<br />
but when i read about the new <a href="http://labs.adobe.com/technologies/stratus/" target="_blank">stratus service</a> a few days ago i couldn't wait to get my hands on it. for those who haven't heard of it: it's a service which provides information to the flash player/air instance to communicate peer-to-peer to another remote instance. before this stratus beta started there was no way of using the new <a href="http://download.macromedia.com/pub/labs/flashplayer10/flashplayer10_rtmfp_faq_070208.pdf" target="_blank">rtmfp</a> (an udp-based network protocol which came with fp10) at all.</p>
<p>after creating a small one-way microphone-chat i wondered how to exchange arbitrary data between the peers. the adobe stratus site reads about the use of rtmfp: "A video chat application, Multi-player game, Voice Over IP" - ok, so while the first and last of that list is in fact quite the same (NetStream.attachCamera() and attachAudio()) and greatly covered by jozsef vass' article "<a href="http://www.adobe.com/devnet/flashplayer/articles/rtmfp_stratus_app.html" target="_blank">Stratus service for developing end-to-end applications using RTMFP in Flash Player</a>",  there are no resources about how to exchange data other than video and audio. or are there?!</p>
<p>in the fp10 api i stumbled upon NetStream.send() which was previously used to communicate with the FMS only, i guess. so like with ExternalInterface you can call functions outside of flash's sandbox: so not javascript this time, but actionscript on other peers. (:<br />
to be more specific: you call functions on the NetStream.client which is of type Object - so you can put there whatever you want. to a function of this client-object you can pass as many arguments as you like, as long as they are of native types.</p>
<p>you'll find a short example after the jump:</p>
<p><span id="more-53"></span></p>
<p>the premise of this example is an established rtmfp-NetConnection (how to do so you can read in vass' article linked above):</p>
<p style="padding-left: 30px;"><em>on the sending peer</em>:</p>
<p style="padding-left: 30px;"><code>var netStream:NetStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);<br />
netStream.send("receiverFunction", "foo");</code></p>
<p style="padding-left: 30px;"><em>on the receiving peer</em>:</p>
<p style="padding-left: 30px;"><code>var netStream:NetStream = new NetStream(nc, id_of_sending_peer);<br />
var clientObj:Object = new Object();<br />
clientObj.receiverFunction = function(arg1:String):void{ trace(arg1); }<br />
netStream.client = clientObj;</code></p>
<p>so every time the sender's NetStream calls send("receiverFunction", ...) the receiving peer outputs the incoming argument in the console.<br />
but that works for native types and objects only. that reduces the communication to only Booleans, ints, Numbers, Strings, Vectors and Arrays (and the others i have forgotten).</p>
<p>in the second part of this article i'll show you how to send objects of your custom classes back and forth between the peers.</p>
]]></content:encoded>
			<wfw:commentRss>http://krisrok.de/blok/?feed=rss2&amp;p=53</wfw:commentRss>
		</item>
		<item>
		<title>tickytickyturntable</title>
		<link>http://krisrok.de/blok/?p=47</link>
		<comments>http://krisrok.de/blok/?p=47#comments</comments>
		<pubDate>Thu, 16 Oct 2008 16:28:03 +0000</pubDate>
		<dc:creator>kris</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

		<guid isPermaLink="false">http://krisrok.de/blok/?p=47</guid>
		<description><![CDATA[actually sound pitching was the first thing i did as soon as the flash 10 beta came out. now that there were some changes in the sound api i wrote it new from scratch.
the finetuning took a while so that there are no more hickups and noises when changing the pitch fluently as you can [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://krisrok.de/flash?pitch"><img class="alignright size-full wp-image-48" title="turntable" src="http://krisrok.de/_blok/wp-content/uploads/2008/10/turntable.jpg" alt="" width="300" height="300" /></a>actually sound pitching was the first thing i did as soon as the flash 10 beta came out. now that there were some changes in the sound api i wrote it new from scratch.</p>
<p>the finetuning took a while so that there are no more hickups and noises when changing the pitch fluently as you can hear in the provided example.<br />
well, at least i think so. it's only been tested with my local beta standalone player yet. the release version is out since yesterday or so and the <a href="http://www.joeberkovitz.com/blog/2008/10/15/controlling-audio-latency-in-flash-10/" target="_blank">bad news</a> already spread - there are again changes to the sound api causing huge latencies depending on your operating system and your hardware apparently.</p>
<p>whatever. be sure to get the fresh <a href="http://www.adobe.com/de/products/flashplayer/" target="_blank">flash 10 player</a> - no more beta <img src='http://krisrok.de/_blok/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> - and check out the little turntable.</p>
<p>the new SoundPitch class is to really easy-to-use: it extends the regular Sound class and the access works just the same:</p>
<ul>
<li>load a sound via .load(myURLRequest) or .load(mySoundObject)</li>
<li>play the sound via .play()</li>
<li>pitch the sound via .pitch = 0.7</li>
<li>you can also change the buffer's length via .bufferLength = 6</li>
</ul>
<p>get it <a href="http://krisrok.de/flash/classes/de/kris/sound/SoundPitch.as" target="_blank">here</a>! (going to clean the code up  soon <img src='http://krisrok.de/_blok/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://krisrok.de/blok/?feed=rss2&amp;p=47</wfw:commentRss>
		</item>
		<item>
		<title>ripple the shipple</title>
		<link>http://krisrok.de/blok/?p=37</link>
		<comments>http://krisrok.de/blok/?p=37#comments</comments>
		<pubDate>Thu, 09 Oct 2008 10:30:03 +0000</pubDate>
		<dc:creator>kris</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://krisrok.de/blok/?p=37</guid>
		<description><![CDATA[there has been some transformation to the original sphere again. the goal was to maintain the 3d-ish effect of the sphere unlike in the previous flowery example.
just play around a bit with it. for instance, you can change the position of the point the ripples "look at" and of course the position of the light [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://krisrok.de/flash?pbSphere3"><img class="alignright size-full wp-image-38" title="pbsphere3" src="http://krisrok.de/_blok/wp-content/uploads/2008/10/pbsphere3.jpg" alt="" width="300" height="300" /></a>there has been some transformation to the original sphere again. the goal was to maintain the 3d-ish effect of the sphere unlike in the previous flowery example.</p>
<p>just play around a bit with it. for instance, you can change the position of the point the ripples "look at" and of course the position of the light source.<br />
if your eye isn't too critical - regarding the straight circle outline shape of the whole thing - it's pretty neat i think <img src='http://krisrok.de/_blok/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>and again i encourage you to install the newest beta player of <a href="http://labs.adobe.com/downloads/flashplayer10.html" target="_blank">flash 10</a>.<br />
i thought about adding another link to a projector-executable because the flash 10 player plugin hasn't really spread that widely yet. on the other hand it is kind of strange to download a 2.x mb executable just to see a effect designed to run in a browser ;D</p>
]]></content:encoded>
			<wfw:commentRss>http://krisrok.de/blok/?feed=rss2&amp;p=37</wfw:commentRss>
		</item>
		<item>
		<title>lets bend the sphere some more</title>
		<link>http://krisrok.de/blok/?p=31</link>
		<comments>http://krisrok.de/blok/?p=31#comments</comments>
		<pubDate>Wed, 08 Oct 2008 16:18:07 +0000</pubDate>
		<dc:creator>kris</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

		<category><![CDATA[Pixel Bender]]></category>

		<guid isPermaLink="false">http://krisrok.de/blok/?p=31</guid>
		<description><![CDATA[a logical step was to transform the mathematically described surface of the sphere as you can see on the right. in this example - which i like to call flowery sphere - there is a sum of parameters you can play with. again, you'll need flash 10!
the elegance of a sphere is that it looks [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://krisrok.de/flash/?pbSphere2"><img class="size-medium wp-image-32 alignright" title="pbsphere2" src="http://krisrok.de/_blok/wp-content/uploads/2008/10/pbsphere2.jpg" alt="" width="300" height="300" /></a>a logical step was to transform the mathematically described surface of the sphere as you can see on the right. in this example - which i like to call flowery sphere - there is a sum of parameters you can play with. again, you'll need <a href="http://labs.adobe.com/downloads/flashplayer10.html" target="_blank">flash 10</a>!</p>
<p>the elegance of a sphere is that it looks exactly the same from whereever you look. now with the transformed surface this effect is gone - it looks alot flatter than the spheres. also it wouldn't make sense to have a few of them floating around in space as they do in the previous post.</p>
<p>maybe in a later post i'll go into detail of how it all works. but i have another approach in the oven i'd like to finish first <img src='http://krisrok.de/_blok/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://krisrok.de/blok/?feed=rss2&amp;p=31</wfw:commentRss>
		</item>
		<item>
		<title>pixelbent spheres</title>
		<link>http://krisrok.de/blok/?p=4</link>
		<comments>http://krisrok.de/blok/?p=4#comments</comments>
		<pubDate>Tue, 07 Oct 2008 21:23:57 +0000</pubDate>
		<dc:creator>kris</dc:creator>
		
		<category><![CDATA[Actionscript]]></category>

		<category><![CDATA[Pixel Bender]]></category>

		<guid isPermaLink="false">http://krisrok.de/blok/?p=4</guid>
		<description><![CDATA[basing on some experiments some time ago with pixel bender kernels i was able to render a few spheres with local illumination for one light source based on phong:

ambient illumination (as a substitute for all indirect light bouncing around in the scene)
diffuse illumination (lets parts of the surface pointing to the light source be lighter [...]]]></description>
			<content:encoded><![CDATA[<p>basing on some experiments some time ago with pixel bender kernels i was able to render a few spheres with local illumination for one light source based on phong:</p>
<ul>
<li>ambient illumination (as a substitute for all indirect light bouncing around in the scene)</li>
<li>diffuse illumination (lets parts of the surface pointing to the light source be lighter than those pointing somewhere else)</li>
<li>specular illumination (adds highlights - you can simulate different materials with that by playing around with the parameters)</li>
</ul>
<p><a href="http://krisrok.de/flash?pbSphere"><img class="size-medium wp-image-21 alignright" title="pbsphere1" src="http://krisrok.de/_blok/wp-content/uploads/2008/10/pbsphere1.jpg" alt="" width="300" height="300" /></a></p>
<p>that's phong. its all that gets calculated for each pixel. and that's a lot.. you can see that pretty soon as you add spheres.<br />
even with a multicore cpu (which is finally supported by flash player 10, yay!) you're happy to reach a bit over 30 spheres without heavy frame drops.</p>
<p>well. of course a shader isnt the best way to render a sphere because you could do lots of stuff iteratively using the previous calculations. that's a thing you cannot do with pixel bender at all - you don't know in which order the shader runs through the image.<br />
but that is another topic <img src='http://krisrok.de/_blok/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>the <a href="http://labs.adobe.com/downloads/flashplayer10.html" target="_blank">current release of flash 10</a> is needed for this and further examples!</p>
]]></content:encoded>
			<wfw:commentRss>http://krisrok.de/blok/?feed=rss2&amp;p=4</wfw:commentRss>
		</item>
		<item>
		<title>opening sequence</title>
		<link>http://krisrok.de/blok/?p=3</link>
		<comments>http://krisrok.de/blok/?p=3#comments</comments>
		<pubDate>Tue, 07 Oct 2008 18:04:22 +0000</pubDate>
		<dc:creator>kris</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://krisrok.de/blok/?p=3</guid>
		<description><![CDATA[
greetings fellow flash(develop)ers!
finally i got myself to posting a first entry on my blok.
not only that its the first post here - it's also the first content on krisrok.de! i hope you enjoy my little experiments and stuff which will pop up here soon.
ah i should drop some lines to introduce myself to you: currently [...]]]></description>
			<content:encoded><![CDATA[<div class="entry-content">
<p>greetings fellow flash(develop)ers!</p>
<p>finally i got myself to posting a first entry on my blok.</p>
<p>not only that its the first post here - it's also the first content on krisrok.de! i hope you enjoy my little experiments and stuff which will pop up here soon.</p>
<p>ah i should drop some lines to introduce myself to you: currently i’m a 24 year old flash developer working for a middle sized, cozy agency in duesseldorf, germany. my main interests are the features of the upcoming flash cs4, especially pixel bender at the moment. so much for now - you’ll read more about that soon enough <img class="wp-smiley" src="../wp-includes/images/smilies/icon_wink.gif" alt=";)" /></div>
]]></content:encoded>
			<wfw:commentRss>http://krisrok.de/blok/?feed=rss2&amp;p=3</wfw:commentRss>
		</item>
	</channel>
</rss>
