<?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>debit.nl</title>
	<atom:link href="http://blog.debit.nl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.debit.nl</link>
	<description>Freelance developer</description>
	<lastBuildDate>Wed, 30 Jun 2010 21:01:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>mDNS daap announce AIR 2.0</title>
		<link>http://blog.debit.nl/2010/06/mdns-daap-announce-air-2-0/</link>
		<comments>http://blog.debit.nl/2010/06/mdns-daap-announce-air-2-0/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 19:34:16 +0000</pubDate>
		<dc:creator>Bernard</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Source]]></category>

		<guid isPermaLink="false">http://blog.debit.nl/?p=110</guid>
		<description><![CDATA[This morning I woke up with the need to try something new.
Never had the time to play with the new AIR 2.0 features or most of the new FP 10.1 features.
So I had to create something that is useful (for me at least) and uses some (in this case just one  ) new feature [...]]]></description>
			<content:encoded><![CDATA[<p>This morning I woke up with the need to try something new.<br />
Never had the time to play with the new AIR 2.0 features or most of the new FP 10.1 features.<br />
So I had to create something that is useful (for me at least) and uses some (in this case just one <img src='http://blog.debit.nl/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) new feature of AIR 2.0.<br />
This nice new class is called DatagramSocket. With this class you can send UDP packages... wait... UDP <img src='http://blog.debit.nl/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
<span id="more-110"></span><br />
To make a long story short... I've read some RFC pages (not the whole document) about mDNS and used wireshark to analyze some mDNS packages.<br />
The result is a class which you can use to announce a daap share in your local network.<br />
For me this is very handy because I now can listen to my home iTunes at any location.</p>
<p>The class:</p>
<pre class="actionscript">&nbsp;
package nl.<span style="color: #006600;">debit</span>.<span style="color: #006600;">net</span>.<span style="color: #006600;">bonjour</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">TimerEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">DatagramSocket</span>;
	<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;">Timer</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DaapAnnouncer
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _aSocket:DatagramSocket;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _ip:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _port:<span style="color: #0066CC;">int</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _ttl:<span style="color: #0066CC;">int</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_name</span>:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _timer:Timer;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> DaapAnnouncer<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>, ip:<span style="color: #0066CC;">String</span>, port:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">3689</span>, ttl:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">120</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">_name</span> = <span style="color: #0066CC;">name</span>;
			_ip = ip;
			_port = port;
			_ttl = ttl;
&nbsp;
			init<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> 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>
			_aSocket = <span style="color: #000000; font-weight: bold;">new</span> DatagramSocket<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_timer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_ttl / <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> * <span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>;
			_timer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>, sendAnnounceData<span style="color: #66cc66;">&#41;</span>;
			_timer.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			sendAnnounceData<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</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> sendAnnounceData<span style="color: #66cc66;">&#40;</span>event:TimerEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_aSocket.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span>getAnnounceBytes<span style="color: #66cc66;">&#40;</span>_ttl<span style="color: #66cc66;">&#41;</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #ff0000;">&quot;224.0.0.251&quot;</span>,<span style="color: #cc66cc;">5353</span><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;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_timer.<span style="color: #006600;">running</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #b1b100;">return</span>;
&nbsp;
			_timer.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			sendAnnounceData<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span><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;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_timer.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_aSocket.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span>getAnnounceBytes<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #ff0000;">&quot;224.0.0.251&quot;</span>,<span style="color: #cc66cc;">5353</span><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> dispose<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_timer.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>, sendAnnounceData<span style="color: #66cc66;">&#41;</span>;
			_timer = <span style="color: #000000; font-weight: bold;">null</span>;
			_aSocket = <span style="color: #000000; font-weight: bold;">null</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getAnnounceBytes<span style="color: #66cc66;">&#40;</span>ttl:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:ByteArray
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> bytes:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x00<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Transaction ID: 0x0000</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x8400<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Flags</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x00<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Question</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x03<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Answer RRs</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x00<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Authority RRs</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x01<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Additional RRs</span>
&nbsp;
			writeString<span style="color: #66cc66;">&#40;</span>bytes, <span style="color: #0066CC;">_name</span> + <span style="color: #ff0000;">&quot;._daap._tcp.local&quot;</span><span style="color: #66cc66;">&#41;</span>;
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x00<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">//SRV record</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x21<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Type</span>
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x80<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// FlushCache</span>
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x01<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Class IN</span>
			bytes.<span style="color: #006600;">writeUnsignedInt</span><span style="color: #66cc66;">&#40;</span>ttl<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Time to live</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span> + _ip.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Data length</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x00<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//priority</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x00<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//weight</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>_port<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//port</span>
			writeString<span style="color: #66cc66;">&#40;</span>bytes, _ip<span style="color: #66cc66;">&#41;</span>;
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x00<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//end</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">//TXT Record</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0xC00C<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Name ^^^</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x10<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Type TXT</span>
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x80<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Flush Cache</span>
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x01<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Class IN</span>
			bytes.<span style="color: #006600;">writeUnsignedInt</span><span style="color: #66cc66;">&#40;</span>ttl<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//TTL</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x01<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Data length</span>
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x00<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Data</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">//PTR Record</span>
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0xC0<span style="color: #66cc66;">&#41;</span>;
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x0D + <span style="color: #0066CC;">_name</span>.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span>;
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x0C<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Type PTR</span>
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x00<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Flush Cache</span>
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x01<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Class IN</span>
			bytes.<span style="color: #006600;">writeUnsignedInt</span><span style="color: #66cc66;">&#40;</span>ttl<span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//TTL</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x02<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Data length</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0xC00C<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Data </span>
&nbsp;
			<span style="color: #808080; font-style: italic;">//Additional Record</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0xC00C<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Name ^^^</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x2F<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Type NSEC</span>
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x80<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Flush Cache</span>
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x01<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Class IN</span>
			bytes.<span style="color: #006600;">writeUnsignedInt</span><span style="color: #66cc66;">&#40;</span>ttl<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//TTL</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0x09<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Data length</span>
			bytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>0xC00C<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Data Next domain name</span>
			bytes.<span style="color: #006600;">writeUnsignedInt</span><span style="color: #66cc66;">&#40;</span>0x50000<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Dunno</span>
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x80<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// RR type TXT</span>
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x00<span style="color: #66cc66;">&#41;</span>;
			bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x40<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// RR type SRV</span>
&nbsp;
			<span style="color: #b1b100;">return</span> bytes;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> writeString<span style="color: #66cc66;">&#40;</span>bytes:ByteArray, <span style="color: #0066CC;">string</span>:<span style="color: #0066CC;">String</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> ar:<span style="color: #0066CC;">Array</span> = <span style="color: #0066CC;">string</span>.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> len:<span style="color: #0066CC;">int</span> = ar.<span style="color: #0066CC;">length</span>;
&nbsp;
			<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i &lt; len; i++<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				bytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>ar<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> as <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span>;
				bytes.<span style="color: #006600;">writeUTFBytes</span><span style="color: #66cc66;">&#40;</span>ar<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>The code needs some cleaning but I think the idea is obvious.</p>
<p>A Simple AIR example: <a href="http://blog.debit.nl/downloads/DaapAnnounce.air">download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.debit.nl/2010/06/mdns-daap-announce-air-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using ByteArrays in Actionscript and Alchemy</title>
		<link>http://blog.debit.nl/2009/03/using-bytearrays-in-actionscript-and-alchemy/</link>
		<comments>http://blog.debit.nl/2009/03/using-bytearrays-in-actionscript-and-alchemy/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 22:23:55 +0000</pubDate>
		<dc:creator>Bernard</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Alchemy]]></category>
		<category><![CDATA[Source]]></category>

		<guid isPermaLink="false">http://blog.debit.nl/?p=79</guid>
		<description><![CDATA[A few days ago I got the question how I did the transfer of data between Actionscript and C (Alchemy).
There are a few ways to push ByteArrays back and forth, I will give some examples of the methods I used.


fopen and supplyFile
Alchemy C:
#include
#include 
&#160;
#include &#34;AS3.h&#34;
&#160;
static AS3_Val readFile&#40;void* self, AS3_Val args&#41;
&#123;
	char * fileName;
	FILE * file;
	long fileSize;
	char [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I got the question how I did the transfer of data between Actionscript and C (Alchemy).<br />
There are a few ways to push ByteArrays back and forth, I will give some examples of the methods I used.<br />
<span id="more-79"></span><br />
<strong><br />
fopen and supplyFile</strong></p>
<p>Alchemy C:</p>
<pre class="c"><span style="color: #339933;">#include</span>
<span style="color: #339933;">#include </span>
&nbsp;
<span style="color: #339933;">#include &quot;AS3.h&quot;</span>
&nbsp;
<span style="color: #993333;">static</span> AS3_Val readFile<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span>* self, AS3_Val args<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #993333;">char</span> * fileName;
	FILE * file;
	<span style="color: #993333;">long</span> fileSize;
	<span style="color: #993333;">char</span> * buffer;
&nbsp;
	AS3_ArrayValue<span style="color: #66cc66;">&#40;</span>args, <span style="color: #ff0000;">&quot;StrType&quot;</span>, &amp;fileName<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	file = fopen<span style="color: #66cc66;">&#40;</span>fileName,<span style="color: #ff0000;">&quot;rb&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//Get file size</span>
	fseek <span style="color: #66cc66;">&#40;</span>file, <span style="color: #cc66cc;">0</span>, SEEK_END<span style="color: #66cc66;">&#41;</span>;
	fileSize = ftell<span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">&#41;</span>;
	rewind<span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//Allocate buffer</span>
	buffer = <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span>*<span style="color: #66cc66;">&#41;</span> malloc<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span><span style="color: #66cc66;">&#41;</span>*fileSize<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//Read file into buffer</span>
	fread<span style="color: #66cc66;">&#40;</span>buffer, <span style="color: #cc66cc;">1</span>, fileSize, file<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//close file and free allocated buffer</span>
	fclose <span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">&#41;</span>;
	free <span style="color: #66cc66;">&#40;</span>buffer<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">return</span> AS3_String<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span>*<span style="color: #66cc66;">&#41;</span>buffer<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	AS3_Val readMethod = AS3_Function<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">NULL</span>, readFile<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	AS3_Val result = AS3_Object<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;readFile: AS3ValType&quot;</span>, readMethod<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	AS3_Release<span style="color: #66cc66;">&#40;</span>readMethod<span style="color: #66cc66;">&#41;</span>;
	AS3_LibInit<span style="color: #66cc66;">&#40;</span>result<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>Actionscript:</p>
<pre class="actionscript">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> cmodule.<span style="color: #006600;">dataTest1</span>.<span style="color: #006600;">CLibInit</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;		
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> loader:CLibInit = <span style="color: #000000; font-weight: bold;">new</span> CLibInit<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> lib:<span style="color: #0066CC;">Object</span> = loader.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<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>;
			byteArray.<span style="color: #006600;">writeUTFBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Hello World!&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			loader.<span style="color: #006600;">supplyFile</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;testFile.txt&quot;</span>, byteArray<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>lib.<span style="color: #006600;">readFile</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;testFile.txt&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>The method of reading a "file" as shown above is read-only in C. That's not because I opened the file "rb" (Read Binary) that's just the way it is. But as you can see it's a really simple solution to read data in C. The bytearray you provide can be any bytearray you like, for example: data from a FileReference.<br />
The filename is a unique identifier for the bytearray. You could just use fopen("testFile.txt","rb") in C and not give the filename as an argument.</p>
<p><strong><br />
Memory allocation in C with direct access in Actionscript (FAST!!)</strong></p>
<p>Alchemy C:</p>
<pre class="c"><span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &quot;AS3.h&quot;</span>
&nbsp;
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span>* buffer;
<span style="color: #993333;">int</span> bufferSize;
&nbsp;
<span style="color: #993333;">static</span> AS3_Val initByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span>* self, AS3_Val args<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
&nbsp;
	AS3_ArrayValue<span style="color: #66cc66;">&#40;</span>args, <span style="color: #ff0000;">&quot;IntType&quot;</span>, &amp;bufferSize<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//Allocate buffer of size &quot;bufferSize&quot;</span>
	buffer = <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span>*<span style="color: #66cc66;">&#41;</span>malloc<span style="color: #66cc66;">&#40;</span>bufferSize*<span style="color: #993333;">sizeof</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//return pointer to the location in memory</span>
	<span style="color: #b1b100;">return</span> AS3_Int<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span><span style="color: #66cc66;">&#41;</span>buffer<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #993333;">static</span> AS3_Val writeData<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span>* self, AS3_Val args<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #993333;">char</span> *tempBuffer;
	AS3_ArrayValue<span style="color: #66cc66;">&#40;</span>args, <span style="color: #ff0000;">&quot;StrType&quot;</span>, &amp;tempBuffer<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//copy string to buffer</span>
	strcpy<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span>*<span style="color: #66cc66;">&#41;</span>buffer, <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span>*<span style="color: #66cc66;">&#41;</span>tempBuffer<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">return</span> AS3_String<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span>*<span style="color: #66cc66;">&#41;</span>tempBuffer<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #993333;">static</span> AS3_Val clearByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span>* self, AS3_Val args<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//free the buffer</span>
	free<span style="color: #66cc66;">&#40;</span>buffer<span style="color: #66cc66;">&#41;</span>;
	*buffer = <span style="color: #cc66cc;">0</span>;
	<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	AS3_Val initByteArrayMethod = AS3_Function<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">NULL</span>, initByteArray<span style="color: #66cc66;">&#41;</span>;
	AS3_Val writeDataMethod = AS3_Function<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">NULL</span>, writeData<span style="color: #66cc66;">&#41;</span>;
	AS3_Val clearByteArrayMethod = AS3_Function<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">NULL</span>, clearByteArray<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	AS3_Val result = AS3_Object<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;initByteArray:AS3ValType, writeData:AS3ValType, clearByteArray:AS3ValType&quot;</span>, initByteArrayMethod, writeDataMethod, clearByteArrayMethod<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	AS3_Release<span style="color: #66cc66;">&#40;</span>initByteArrayMethod<span style="color: #66cc66;">&#41;</span>;
	AS3_Release<span style="color: #66cc66;">&#40;</span>writeDataMethod<span style="color: #66cc66;">&#41;</span>;
	AS3_Release<span style="color: #66cc66;">&#40;</span>clearByteArrayMethod<span style="color: #66cc66;">&#41;</span>;
	AS3_LibInit<span style="color: #66cc66;">&#40;</span>result<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>Actionscript:</p>
<pre class="actionscript">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> cmodule.<span style="color: #006600;">dataTest2</span>.<span style="color: #006600;">CLibInit</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;		
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _dataPosition:uint;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> loader:CLibInit = <span style="color: #000000; font-weight: bold;">new</span> CLibInit<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> lib:<span style="color: #0066CC;">Object</span> = loader.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> ns:Namespace = <span style="color: #000000; font-weight: bold;">new</span> Namespace<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cmodule.dataTest2&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> byteArray:ByteArray = <span style="color: #66cc66;">&#40;</span>ns::gstate<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">ds</span>; <span style="color: #808080; font-style: italic;">//point to memory</span>
&nbsp;
			_dataPosition = lib.<span style="color: #006600;">initByteArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//This is the position of the data in memory			</span>
&nbsp;
			lib.<span style="color: #006600;">writeData</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Hello &quot;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//example function to write data in C</span>
&nbsp;
			byteArray.<span style="color: #0066CC;">position</span> = _dataPosition + <span style="color: #cc66cc;">6</span>; <span style="color: #808080; font-style: italic;">//Move to the next free location</span>
&nbsp;
			byteArray.<span style="color: #006600;">writeUTFBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;World!&quot;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//write text at the current position</span>
&nbsp;
			byteArray.<span style="color: #0066CC;">position</span> = _dataPosition; <span style="color: #808080; font-style: italic;">//reset position</span>
&nbsp;
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>byteArray.<span style="color: #006600;">readUTFBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//read bytearray</span>
&nbsp;
			lib.<span style="color: #006600;">clearByteArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Free the bytearray</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>This method is the fastest method to use data between C and Actionscript. In C you allocate a chunk of memory of the given size and it's position is returned to Actionscript. In Actionscript you can set a reference to the Alchemy memory as shown with the namespace.<br />
You MUST postition the bytearray to the position given back by C, because that's where your data is.</p>
<p>I've tested this method with coloring a 640x400px bitmap looping over the rainbow colors.<br />
I applied the bytearray to the bitmap with setPixels(ba:ByteArray, rect:Rectangle); and filled the 640x400 bytearray in both Actionscript and C. I was very surprised about the difference in speed.<br />
In Actionscript the framerate maxed out at 10fps, but filling the bytearray in C gave me a rate of 60fps (max on my mac).</p>
<p><strong><br />
funopen and bytearray pointer</strong></p>
<p>Alchemy C:</p>
<pre class="c"><span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &quot;AS3.h&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Does a FILE * read against a ByteArray */</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> readByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span> *cookie, <span style="color: #993333;">char</span> *dst, <span style="color: #993333;">int</span> size<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> AS3_ByteArray_readBytes<span style="color: #66cc66;">&#40;</span>dst, <span style="color: #66cc66;">&#40;</span>AS3_Val<span style="color: #66cc66;">&#41;</span>cookie, size<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Does a FILE * write against a ByteArray */</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> writeByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span> *cookie, <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> *src, <span style="color: #993333;">int</span> size<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> AS3_ByteArray_writeBytes<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>AS3_Val<span style="color: #66cc66;">&#41;</span>cookie, <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span> *<span style="color: #66cc66;">&#41;</span>src, size<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Does a FILE * lseek against a ByteArray */</span>
<span style="color: #993333;">static</span> fpos_t seekByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span> *cookie, fpos_t offs, <span style="color: #993333;">int</span> whence<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> AS3_ByteArray_seek<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>AS3_Val<span style="color: #66cc66;">&#41;</span>cookie, offs, whence<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Does a FILE * close against a ByteArray */</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> closeByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span> * cookie<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	AS3_Val zero = AS3_Int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/* just reset the position */</span>
	AS3_SetS<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>AS3_Val<span style="color: #66cc66;">&#41;</span>cookie, <span style="color: #ff0000;">&quot;position&quot;</span>, zero<span style="color: #66cc66;">&#41;</span>;
	AS3_Release<span style="color: #66cc66;">&#40;</span>zero<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #993333;">static</span> AS3_Val doMagic<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span>* self, AS3_Val args<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	FILE * file;
	<span style="color: #993333;">long</span> fileSize;
	<span style="color: #993333;">char</span> * buffer;
	<span style="color: #993333;">void</span> * dest;
&nbsp;
	AS3_ArrayValue<span style="color: #66cc66;">&#40;</span>args, <span style="color: #ff0000;">&quot;AS3ValType&quot;</span>, &amp;dest<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	file = funopen<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span> *<span style="color: #66cc66;">&#41;</span>dest, readByteArray, writeByteArray, seekByteArray, closeByteArray<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #993333;">char</span> buffer2<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">'H'</span>,<span style="color: #ff0000;">'e'</span>,<span style="color: #ff0000;">'l'</span>,<span style="color: #ff0000;">'l'</span>,<span style="color: #ff0000;">'o'</span>,<span style="color: #ff0000;">' '</span>,<span style="color: #ff0000;">'W'</span>,<span style="color: #ff0000;">'o'</span>,<span style="color: #ff0000;">'r'</span>,<span style="color: #ff0000;">'l'</span>,<span style="color: #ff0000;">'d'</span>,<span style="color: #ff0000;">'!'</span><span style="color: #66cc66;">&#125;</span>;
&nbsp;
	fwrite <span style="color: #66cc66;">&#40;</span>buffer2, <span style="color: #cc66cc;">1</span>, <span style="color: #993333;">sizeof</span><span style="color: #66cc66;">&#40;</span>buffer2<span style="color: #66cc66;">&#41;</span>, file<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">// get file size</span>
	fseek <span style="color: #66cc66;">&#40;</span>file, <span style="color: #cc66cc;">0</span>, SEEK_END<span style="color: #66cc66;">&#41;</span>;
	fileSize = ftell<span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">&#41;</span>;
	rewind <span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//Allocate memory for the buffer</span>
	buffer = <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span>*<span style="color: #66cc66;">&#41;</span> malloc <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span><span style="color: #66cc66;">&#41;</span>*fileSize<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//Copy the file into the buffer</span>
	fread <span style="color: #66cc66;">&#40;</span>buffer, <span style="color: #cc66cc;">1</span>, fileSize, file<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//Close file and clear</span>
	fclose <span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">&#41;</span>;
	free <span style="color: #66cc66;">&#40;</span>buffer<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">return</span> AS3_String<span style="color: #66cc66;">&#40;</span>buffer<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	AS3_Val doMagicMethod = AS3_Function<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">NULL</span>, doMagic<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	AS3_Val result = AS3_Object<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;doMagic:AS3ValType&quot;</span>, doMagicMethod<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	AS3_Release<span style="color: #66cc66;">&#40;</span>doMagicMethod<span style="color: #66cc66;">&#41;</span>;
	AS3_LibInit<span style="color: #66cc66;">&#40;</span>result<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>ActionScript:</p>
<pre class="actionscript">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> cmodule.<span style="color: #006600;">dataTest3</span>.<span style="color: #006600;">CLibInit</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;		
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> loader:CLibInit = <span style="color: #000000; font-weight: bold;">new</span> CLibInit<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> lib:<span style="color: #0066CC;">Object</span> = loader.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<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>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> result:<span style="color: #0066CC;">String</span> = lib.<span style="color: #006600;">doMagic</span><span style="color: #66cc66;">&#40;</span>byteArray<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>result<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>byteArray.<span style="color: #006600;">readUTFBytes</span><span style="color: #66cc66;">&#40;</span>byteArray.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>As you can see you pass a ByteArray to C and it uses funopen to open the bytearray as a FILE. The functions provided at the funopen function map the FILE functions to bytearray functions, so the bytearray acts as a file.<br />
In ActionScript you can see that the bytearray holds the data C has writen to it.<br />
This way you can use normal FILE function in C and for example save the data in Actionscript with the FileReference.</p>
<p>If you have any questions or remarks please let me hear them!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.debit.nl/2009/03/using-bytearrays-in-actionscript-and-alchemy/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>MP3 encoder in Flash with Alchemy</title>
		<link>http://blog.debit.nl/2009/03/mp3-encoder-in-flash-with-alchemy/</link>
		<comments>http://blog.debit.nl/2009/03/mp3-encoder-in-flash-with-alchemy/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 14:44:42 +0000</pubDate>
		<dc:creator>Bernard</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Alchemy]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.debit.nl/?p=67</guid>
		<description><![CDATA[A week ago I started playing with Adobe Alchemy. First just a few return values or simple calculations.
After a few days of playing and testing I thought it would be nice to have a MP3 Encoder in flash.
With the new Sound.extract method in Actionscript you can get raw data like a "WAV" but there is [...]]]></description>
			<content:encoded><![CDATA[<p>A week ago I started playing with Adobe Alchemy. First just a few return values or simple calculations.<br />
After a few days of playing and testing I thought it would be nice to have a MP3 Encoder in flash.<br />
With the new Sound.extract method in Actionscript you can get raw data like a "WAV" but there is no easy way to compress this data.</p>
<p>I started searching for C code which implements a MP3 Encoder and found the 8Hz MP3 implementation.<br />
I could have used LAME, but hey.. have you looked at the file count!<br />
The 8Hz implementation uses about 10 files, so it's readable. It's not the best encoder, but good enough to test the possibilities.</p>
<p>I was very surprised that the 8Hz code would compile with llvm-gcc (Alchemy)! That is a good starting point, now I only have to rewrite some code to get input from and output to Actionscript.</p>
<p>The original source used fopen to read and write files. This isn't possible with Alchemy so I replaced fopen with funopen and gave a pointer to Actionscript bytearrays.</p>
<p>The next problem I encountered was the execution timeout in Flash. When encoding large WAV files (more then 30 seconds of sound on my MacBook Pro) the flashplayer will trigger an error about exceeding the maximum execution time. I tried to alter it with the compiler option "-default-script-limits" but no luck (maybe it has something to do with Alchemy).<br />
But it forced me to take a deeper look in the encoding source. I've rewritten the layer3.c file to process a few frames and then give feedback to Actionscript. This way no timeout occurs.</p>
<p>I'm still working on speed optimization, because encoding is slow at the moment.<br />
I will keep you updated!</p>
<p>Here is the first version:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_mp3encoder_v1_503468946"
			class="flashmovie"
			width="260"
			height="80">
	<param name="movie" value="/wp-content/uploads/2009/03/mp3encoder_v1.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/wp-content/uploads/2009/03/mp3encoder_v1.swf"
			name="fm_mp3encoder_v1_503468946"
			width="260"
			height="80">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer">Get Adobe Flash player</a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://blog.debit.nl/2009/03/mp3-encoder-in-flash-with-alchemy/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>MP3 to SWF converter in Actionscript 3</title>
		<link>http://blog.debit.nl/2009/02/mp3-to-swf-converter-in-actionscript-3/</link>
		<comments>http://blog.debit.nl/2009/02/mp3-to-swf-converter-in-actionscript-3/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 13:02:52 +0000</pubDate>
		<dc:creator>Bernard</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.debit.nl/?p=31</guid>
		<description><![CDATA[A while ago I was playing with SWF generation within Flash itself.
I read the Adobe SWF specs and now I'm able to generate SWF's from FLV's and MP3's or both.
A simple Flash 10 example, haven't tested all possible MP3 rates so if someone encounters a bug, please let me know.
(Just found out that some MP3's [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I was playing with SWF generation within Flash itself.<br />
I read the Adobe SWF specs and now I'm able to generate SWF's from FLV's and MP3's or both.</p>
<p>A simple Flash 10 example, haven't tested all possible MP3 rates so if someone encounters a bug, please let me know.<br />
(Just found out that some MP3's with embedded art-work won't work... added to my TODO's).</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_blogmp3test_1147310249"
			class="flashmovie"
			width="250"
			height="74">
	<param name="movie" value="http://blog.debit.nl/wp-content/uploads/2009/02/blogmp3test.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://blog.debit.nl/wp-content/uploads/2009/02/blogmp3test.swf"
			name="fm_blogmp3test_1147310249"
			width="250"
			height="74">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer">Get Adobe Flash player</a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Code snippet which writes the MP3 data to a SWF bytearray:</p>
<pre class="actionscript"><span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>mp3.<span style="color: #006600;">audioFrames</span>.<span style="color: #0066CC;">length</span> &gt; currentAudioFrame<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> needSamples:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0.001</span> * <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span>/<span style="color: #66cc66;">&#40;</span>__frameRate<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>*i<span style="color: #66cc66;">&#41;</span> * audioRate;
	<span style="color: #000000; font-weight: bold;">var</span> startSamples:<span style="color: #0066CC;">int</span> = currentSamples;
	<span style="color: #000000; font-weight: bold;">var</span> audioData:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>mp3.<span style="color: #006600;">audioFrames</span>.<span style="color: #0066CC;">length</span> &gt; currentAudioFrame &amp;&amp; currentSamples&lt; needSamples<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> aframe:AudioFrame = AudioFrame<span style="color: #66cc66;">&#40;</span>mp3.<span style="color: #006600;">audioFrames</span><span style="color: #66cc66;">&#91;</span>currentAudioFrame<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
		audioData.<span style="color: #006600;">writeBytes</span><span style="color: #66cc66;">&#40;</span>aframe.<span style="color: #006600;">frameData</span><span style="color: #66cc66;">&#41;</span>;
		currentSamples = <span style="color: #66cc66;">&#40;</span>currentAudioFrame<span style="color: #cc66cc;">+1</span><span style="color: #66cc66;">&#41;</span> * <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">576</span>*<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
		currentAudioFrame++;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> samples:<span style="color: #0066CC;">int</span> = currentSamples - startSamples;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">seek</span>:<span style="color: #0066CC;">int</span> = startSamples ? needSamples - startSamples : <span style="color: #cc66cc;">0</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> af:AudioFrame = mp3.<span style="color: #006600;">audioFrames</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> as AudioFrame;
	_swfBytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>createHeader<span style="color: #66cc66;">&#40;</span>SWFTags.<span style="color: #006600;">SOUNDSTREAMBLOCK</span>,<span style="color: #cc66cc;">63</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	_swfBytes.<span style="color: #006600;">writeInt</span><span style="color: #66cc66;">&#40;</span>audioData.<span style="color: #006600;">length</span><span style="color: #cc66cc;">+4</span><span style="color: #66cc66;">&#41;</span>;
	_swfBytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>samples<span style="color: #66cc66;">&#41;</span>;
	_swfBytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">seek</span><span style="color: #66cc66;">&#41;</span>;
	_swfBytes.<span style="color: #006600;">writeBytes</span><span style="color: #66cc66;">&#40;</span>audioData<span style="color: #66cc66;">&#41;</span>;
	_swfBytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>createHeader<span style="color: #66cc66;">&#40;</span>SWFTags.<span style="color: #006600;">PLACE_OBJECT2</span>,<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Place frame data</span>
	_swfBytes.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
	_swfBytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//depth</span>
	_swfBytes.<span style="color: #006600;">writeShort</span><span style="color: #66cc66;">&#40;</span>createHeader<span style="color: #66cc66;">&#40;</span>SWFTags.<span style="color: #006600;">SHOWFRAME</span>,<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	i++;
<span style="color: #66cc66;">&#125;</span></pre>
<p>This way I write all SWF headers the correct way and not like most other code out there which uses a precompiled SWF and replace the sound object.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.debit.nl/2009/02/mp3-to-swf-converter-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Doc? Air Local LiveDocs</title>
		<link>http://blog.debit.nl/2009/02/doc-air-local-livedocs/</link>
		<comments>http://blog.debit.nl/2009/02/doc-air-local-livedocs/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 13:12:29 +0000</pubDate>
		<dc:creator>Bernard</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.debit.nl/?p=14</guid>
		<description><![CDATA[Doc? is an Air application that allows you to view your documentation outside of your IDE.
It supports Flash CS3 documentation, Flash CS4, Flex and ASDoc.
Searching can be done by keyword or by regular expression!
Doc? provides two plugins, one for Flash and one for Eclipse (Flex, FDT etc..). These plugins send the selected text to Doc? [...]]]></description>
			<content:encoded><![CDATA[<p>Doc? is an Air application that allows you to view your documentation outside of your IDE.<br />
It supports Flash CS3 documentation, Flash CS4, Flex and ASDoc.</p>
<p>Searching can be done by keyword or by regular expression!<br />
Doc? provides two plugins, one for Flash and one for Eclipse (Flex, FDT etc..). These plugins send the selected text to Doc? and Doc? will search it's database for matching items.</p>
<p>I love it <img src='http://blog.debit.nl/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><a title="http://www.airdoc.be" href="http://www.airdoc.be" target="_blank">http://www.airdoc.be</a></p>
<p>Screenshot with the PV3D ASdocs imported:</p>
<div id="attachment_15" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.debit.nl/wp-content/uploads/2009/02/screen_custom_asdocs.png"><img class="size-medium wp-image-15" title="Papervion API in Doc?" src="http://blog.debit.nl/wp-content/uploads/2009/02/screen_custom_asdocs-300x163.png" alt="Papervion API in Doc?" width="300" height="163" /></a><p class="wp-caption-text">Papervion API in Doc?</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.debit.nl/2009/02/doc-air-local-livedocs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Replace HTML encoded characters with their original ones</title>
		<link>http://blog.debit.nl/2009/02/replace-html-encoded-characters-with-their-original-ones/</link>
		<comments>http://blog.debit.nl/2009/02/replace-html-encoded-characters-with-their-original-ones/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 12:57:31 +0000</pubDate>
		<dc:creator>Bernard</dc:creator>
				<category><![CDATA[Actionscript]]></category>

		<guid isPermaLink="false">http://blog.debit.nl/?p=6</guid>
		<description><![CDATA[Just a simple regular expression to replace all HTML encoded characters with their original ones.
var testString:String = &#34;This is a test with a &#38;#8211; character and a &#38;#8217;&#34;;
testString = testString.replace&#40;/&#38;#([0-9]+);/g, replaceCharacters);
&#160;
private function replaceCharacters&#40;...args&#41;:String
&#123;
	return String.fromCharCode&#40;parseInt&#40;args&#91;1&#93;&#41;&#41;;
&#125;
]]></description>
			<content:encoded><![CDATA[<p>Just a simple regular expression to replace all HTML encoded characters with their original ones.</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> testString:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;This is a test with a &amp;#8211; character and a &amp;#8217;&quot;</span>;
testString = testString.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span>/&amp;<span style="color: #808080; font-style: italic;">#([0-9]+);/g, replaceCharacters);</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> replaceCharacters<span style="color: #66cc66;">&#40;</span>...<span style="color: #006600;">args</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">String</span>.<span style="color: #0066CC;">fromCharCode</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">parseInt</span><span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.debit.nl/2009/02/replace-html-encoded-characters-with-their-original-ones/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Blog online..</title>
		<link>http://blog.debit.nl/2009/02/blog-online/</link>
		<comments>http://blog.debit.nl/2009/02/blog-online/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 12:54:53 +0000</pubDate>
		<dc:creator>Bernard</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.debit.nl/?p=11</guid>
		<description><![CDATA[I thought it was about time to get my own blog online.
Now just thinking... what should I blog about..
]]></description>
			<content:encoded><![CDATA[<p>I thought it was about time to get my own blog online.<br />
Now just thinking... what should I blog about..</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.debit.nl/2009/02/blog-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
