<?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>Maccherone &#187; Code</title>
	<atom:link href="http://maccherone.com/larry/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://maccherone.com/larry</link>
	<description>Like photography, the impact of data visualization, is a function of perspective, focus, and illumination.</description>
	<lastBuildDate>Sun, 11 Mar 2012 12:47:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>The CoffeeScript emperor has no clothes</title>
		<link>http://maccherone.com/larry/2012/02/02/the-coffeescript-emperor-has-no-clothes/</link>
		<comments>http://maccherone.com/larry/2012/02/02/the-coffeescript-emperor-has-no-clothes/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 11:32:05 +0000</pubDate>
		<dc:creator>Larry Maccherone</dc:creator>
				<category><![CDATA[CoffeeScript]]></category>

		<guid isPermaLink="false">http://maccherone.com/larry/?p=292</guid>
		<description><![CDATA[Subtitle: when CoffeeScript rock stars run around naked in public Just because you can do something doesn&#8217;t mean you should. Leaving the parentheses out of your CoffeeScript might make your code look a bit more &#8220;natural&#8221;, but it almost always &#8230; <a href="http://maccherone.com/larry/2012/02/02/the-coffeescript-emperor-has-no-clothes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://maccherone.com/larry/2012/02/02/the-coffeescript-emperor-has-no-clothes/";
		var dzone_title = "The CoffeeScript emperor has no clothes";
		var dzone_style = "1";
		var dzone_blurb = "Subtitle: when CoffeeScript rock stars run around naked in publicJust because you can do something doesn&#8217;t mean you should. Leaving the parentheses out of your CoffeeScript might make your code look a bit more &#8220;natural&#8221;, but it almost...";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div><!--S-ButtonZ 1.1.5 End--><h3>Subtitle: when CoffeeScript rock stars run around naked in public</h3>

<p>Just because you can do something doesn&#8217;t mean you should. Leaving the parentheses out of your CoffeeScript might make your code look a bit more &#8220;natural&#8221;, but it almost always makes the code less readable and in a many cases, it makes it impossible for the CoffeeScript compiler to understand your intent. It&#8217;s more &#8220;natural&#8221; to go around naked but you shouldn&#8217;t. Just like you need to cover your private parts when you go outside, <strong>you should properly cloth your CoffeeScript function/method parameters in parentheses</strong>.</p>

<p>I know&#8230; you want to show that you are a CoffeeScript cool-kid. You can write a one-line list comprehension that is like a brilliant guitar solo. But I think it&#8217;s cooler for my code to be readable and for the compiler to precisely understand what I intend. The list comprehension guitar solo may be showing off but we expect our cool rock stars to show off. However, it&#8217;s uncool (even for rock stars) to be <a href="http://www.forkparty.com/1164/rock-stars">drug-addled running around naked in public</a>. Be the rock star without the drugs&#8230; or running around without your function/method calls properly clothed in parentheses.</p>

<p>In the last few months alone, on StackOverflow, there have a been at least six questions that I have flagged as caused by this issue:</p>

<ul>
<li><a href="http://stackoverflow.com/questions/9098412/coffeescript-calling-a-method-of-returned-object-chaining">Chaining</a></li>
<li><a href="http://stackoverflow.com/questions/7200464/method-call-syntax-in-coffeescript">Calling functions with no parameters</a></li>
<li><a href="http://stackoverflow.com/questions/7532616/multiline-function-calls-in-coffeescript">Lambdas with multiple functions</a></li>
<li><a href="http://stackoverflow.com/questions/4849818/how-do-i-make-a-get-request-using-coffeescript">Help showing code flow with jquery</a></li>
<li><a href="http://stackoverflow.com/questions/7636555/require-a-library-with-configuration-in-coffeescript">Calling a function which calls a function</a></li>
<li><a href="http://stackoverflow.com/questions/6586953/coffeescript-function-call-parameters-and-brackets">Confusing space</a></li>
</ul>

<p>In all of the cases above, there is an idiom that you can&#8217;t precisely/clearly express without parentheses around function/method parameters. Often, the coder realizes that it&#8217;s ambiguous but &#8220;hopes&#8221; that the compiler can figure out his intent. He posts a question on StackOverflow once he is able to show that it cannot. In all of these cases,  the coder has learned CoffeeScript by looking at a bunch of examples that leave out the parentheses and he doesn&#8217;t realize that you <strong>can</strong> put them in&#8230; or he wants to know how the cool-kids express it without them. In each case, the answer is invariably, &#8220;Simply add parentheses and it will work as expected.&#8221;</p>

<p>If this is confusing the compiler and the new users who want to be CoffeeScript cool-kids, we CoffeeScript bloggers should all make an effort to post <strong>all</strong> examples with the parentheses left in. I&#8217;m going so far as to leave them in all of my code and my collaborators seem to appreciate it. If nobody ever needs to read your code, then feel free to walk around naked in a drug-addled state within the privacy of your own home. But as soon as you step out the door, or want anyone else to read your code&#8230;</p>

<p>It&#8217;s perfectly fine to leave them out of if-statements, while-loop, etc. We like our female rock starts to show a little cleavage and some folks get turned on by Mick Jagger&#8217;s tight leather pants.</p>

<p>Chaining (needed for compiler to understand intent)</p>

<p><code>someObject.slideLeft(4).invert().slideUp(10)</code></p>

<p>Calling a parameter-less method (also necessary)</p>

<p><code>someIterator.next()</code></p>

<p>Function/method calling (even when not chaining, for human clarity)</p>

<p><code>someFunction(parameterA, parameterB)</code></p>

<p>&#8230;Even when the last parameter is a callback (Yeah, I know, the CoffeeScript cool-kids think this is ugly and a pain to line up the ending parentheses but it&#8217;s worth it for the clarity gain, IMHO. Suck it up rock star, even Bob Dylan had to adjust his lyrics so his listeners could understand him&#8230; well, maybe Bob Dylan could get away with confusing shit. But face it, <strong>you are NOT as cool as Bob Dylan</strong>&#8230; and coding requires a precision that isn&#8217;t needed in poetry/music. )</p>

<p><code>someMethodNeedingACallback(parameterA, (err, data) -&gt;
    console.log(data)
)</code></p>

<p>Functions with no parameters (could live without this, but IMHO, it&#8217;s more readable with it)</p>

<p><code>f = () -&gt;
    return "hello"  # notice how I also like to say "return". That's another clarity choice.</code></p>

<p>One last argument to try to convince you&#8230; Python is the most readable programming language out there. The Python BDFL has come out time and again in favor of readability even at the expense of conciseness. Python used to have a parentheses-less <code>print</code> statement, but Guido feels so strongly that this was a mistake, that he went through the very painful backward-breaking change to <a href="http://docs.python.org/release/3.0.1/whatsnew/3.0.html">require parentheses for print function calls in Python 3.0</a>. I would go so far as to argue that we should remove this &#8220;feature&#8221; from the CoffeeScript spec but even if we don&#8217;t, we should stop using it.</p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://maccherone.com/larry/2012/02/02/the-coffeescript-emperor-has-no-clothes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introducing coffeedoctest</title>
		<link>http://maccherone.com/larry/2012/01/15/introducing-coffeedoctest/</link>
		<comments>http://maccherone.com/larry/2012/01/15/introducing-coffeedoctest/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 17:25:06 +0000</pubDate>
		<dc:creator>Larry Maccherone</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CoffeeScript]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">http://maccherone.com/larry/?p=286</guid>
		<description><![CDATA[The examples you add to document your project are like a map to the buried treasure that is your library/API/tool/etc. But if the examples are wrong, it&#8217;s like labeling the map with &#8220;promised land&#8221; right over the spot where it &#8230; <a href="http://maccherone.com/larry/2012/01/15/introducing-coffeedoctest/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><!--S-ButtonZ 1.1.5 Start-->
<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://maccherone.com/larry/2012/01/15/introducing-coffeedoctest/";
		var dzone_title = "Introducing coffeedoctest";
		var dzone_style = "1";
		var dzone_blurb = "The examples you add to document your project are like a map to the buried treasure that is your library/API/tool/etc. But if the examples are wrong, it&#8217;s like labeling the map with &#8220;promised land&#8221; right over the spot where it should...";
		//-->
		</script><br />
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div>
<p><!--S-ButtonZ 1.1.5 End-->
<p>The examples you add to document your project are like a map to the buried treasure that is your library/API/tool/etc. But if the examples are wrong, it&#8217;s like labeling the map with &#8220;promised land&#8221; right over the spot where it should say, &#8220;there be dragons&#8221;.</p>
<p>It&#8217;s less about testing your code with your documentation, than the other way around. Make sure that the examples in your documenation stay current with your code. <strong>coffeedoctest</strong> is a way to test your documentation with your code&#8230; to make sure that the map matches the terrain.</p>
<p>If you&#8217;ve spent any time working in Python, then you are probably familiar with <a href="http://docs.python.org/release/2.5.2/lib/module-doctest.html">doctest</a>. Coffeedoctest is built along the same lines.</p>
<p>For entire story visit the <a href="https://github.com/lmaccherone/coffeedoctest">coffeedoctest project page</a> on github.</p>
<div style="clear:both;">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://maccherone.com/larry/2012/01/15/introducing-coffeedoctest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My first Panic! Coda plugin</title>
		<link>http://maccherone.com/larry/2012/01/09/my-first-panic-coda-plugin/</link>
		<comments>http://maccherone.com/larry/2012/01/09/my-first-panic-coda-plugin/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 04:14:03 +0000</pubDate>
		<dc:creator>Larry Maccherone</dc:creator>
				<category><![CDATA[CoffeeScript]]></category>
		<category><![CDATA[Coda]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">http://maccherone.com/larry/?p=252</guid>
		<description><![CDATA[I&#8217;ve been doing more coding in CoffeeScript and as any good craftsman knows, you must sharpen the saw from time to time. This time, I added some convenience commands for doing line manipulation by writing my very own Panic! Coda &#8230; <a href="http://maccherone.com/larry/2012/01/09/my-first-panic-coda-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><!--S-ButtonZ 1.1.5 Start-->
<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://maccherone.com/larry/2012/01/09/my-first-panic-coda-plugin/";
		var dzone_title = "My first Panic! Coda plugin";
		var dzone_style = "1";
		var dzone_blurb = "I&#8217;ve been doing more coding in CoffeeScript and as any good craftsman knows, you must sharpen the saw from time to time. This time, I added some convenience commands for doing line manipulation by writing my very own Panic! Coda plugin.It will allow...";
		//-->
		</script><br />
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div>
<p><!--S-ButtonZ 1.1.5 End-->I&#8217;ve been doing more coding in CoffeeScript and as any good craftsman knows, you must sharpen the saw from time to time. This time, I added some convenience commands for doing line manipulation by writing my very own Panic! Coda plugin.It will allow you to delete, duplicate, and move lines with a keystroke. There is also a convenience shortcut for wrapping a variable in console.log.</p>
<p>It was actually pretty easy using <a href="http://www.panic.com/coda/developer/howto/plugins.php" target="_blank">Panic!&#8217;s Coda Plug-in Creator</a>. I wrote my text manipulation code in javascript as shell scripts that would run under node.js and simply dragged them into the Coda Plug-in Creator.</p>
<p>You can find it on GitHub <a href="https://github.com/lmaccherone/LineCommands.codaplugin" target="_blank">here</a>.
<div style="clear:both;">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://maccherone.com/larry/2012/01/09/my-first-panic-coda-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coda vs WebStorm vs TextMate for CoffeeScript</title>
		<link>http://maccherone.com/larry/2012/01/02/coda-vs-webstorm-vs-textmate-for-coffeescript/</link>
		<comments>http://maccherone.com/larry/2012/01/02/coda-vs-webstorm-vs-textmate-for-coffeescript/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 23:36:55 +0000</pubDate>
		<dc:creator>Larry Maccherone</dc:creator>
				<category><![CDATA[CoffeeScript]]></category>
		<category><![CDATA[Software craftsmanship]]></category>
		<category><![CDATA[Coda]]></category>
		<category><![CDATA[TextMate]]></category>
		<category><![CDATA[WebStorm]]></category>

		<guid isPermaLink="false">http://maccherone.com/larry/?p=248</guid>
		<description><![CDATA[I recently started rewriting all of my PhD tools in CoffeeScript from ActionScript. I&#8217;m loving the python-like syntax and I&#8217;m very happy with the language as well as the ecosystem around CoffeeScript and node.js. Tools are an important part of &#8230; <a href="http://maccherone.com/larry/2012/01/02/coda-vs-webstorm-vs-textmate-for-coffeescript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><!--S-ButtonZ 1.1.5 Start-->
<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://maccherone.com/larry/2012/01/02/coda-vs-webstorm-vs-textmate-for-coffeescript/";
		var dzone_title = "Coda vs WebStorm vs TextMate for CoffeeScript";
		var dzone_style = "1";
		var dzone_blurb = "I recently started rewriting all of my PhD tools in CoffeeScript from ActionScript. I&#8217;m loving the python-like syntax and I&#8217;m very happy with the language as well as the ecosystem around CoffeeScript and node.js. Tools are an important part...";
		//-->
		</script><br />
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div>
<p><!--S-ButtonZ 1.1.5 End-->I recently started rewriting all of my PhD tools in CoffeeScript from ActionScript. I&#8217;m loving the python-like syntax and I&#8217;m very happy with the language as well as the ecosystem around CoffeeScript and node.js. Tools are an important part of the experience so I&#8217;ve played around with several editors/IDE&#8217;s for writing CoffeeScript. Here is a quick comparison.</p>
<h2>Coda</h2>
<p>This is probably my favorite environment right now. I&#8217;m using a <a href="https://github.com/lmaccherone/CoffeeScript.mode">custom CoffeeScript.mode</a> that I forked from <a href="https://github.com/nfiniteset">Sean Durham</a> to add navigator support.</p>
<p>Pros:</p>
<ul>
<li>Nice clean interface written for the Mac</li>
<li>Syntax highlighting that works in both .coffee and CakeFile</li>
<li>Instant startup/shutdown and low resource usage. I can code on battery for 4+ hours on my MacBook Pro.</li>
<li>Preview mode for HTML.</li>
<li>Hackable. I already upgraded the 3rd party mode file. I have thoughts on plugins for running unit tests and reporting code coverage.</li>
</ul>
<p>Cons:</p>
<ul>
<li>Only subversion integration. Personally, I never use the source code integration built into editors and IDE&#8217;s so this is not a problem for me. But EVERYONE uses git for CoffeeScript. I just started using GitHub for Mac. I&#8217;ll see how that goes but I can always use the command line.</li>
<li>No code folding. Again, not a feature that I miss too much because I can put each class into a different file. The navigator is also a decent substitute.</li>
</ul>
<h2>WebStorm</h2>
<p>Pros:</p>
<ul>
<li>Refactoring.</li>
<li>NodeUnit support built in. Nice!!!</li>
<li>Keystrokes that make sense to me. Ctrl-Y means yank this line. It&#8217;s the only one of the three that does that.</li>
</ul>
<p>Cons:</p>
<ul>
<li>Still beta quality</li>
<ul>
<li>The syntax highlighter doesn&#8217;t like multi-line comments &#8220;###&#8221;&#8230;&#8221;###&#8221; to have any &#8220;#&#8221; inside. Until they <a href="http://youtrack.jetbrains.net/issue/RUBY-10124">fix this</a>, I&#8217;m not going to use it again.</li>
<li>My .idea folder got corrupted several times and each time it lost my configuration foo for running nodeunit tests.</li>
</ul>
<li>Heavyweight. It&#8217;s essentially the IntelliJ IDE with java editing (and a bunch of other functionality) removed.</li>
</ul>
<h2>TextMate</h2>
<p>I started writing CoffeeScript in TextMate and I still pull up .coffee files for a quick look in TextMate so this is my backup.</p>
<p>Pros:</p>
<ul>
<li>Syntax highlighting that works. I think TextMate&#8217;s is the basis for the Coda one that I use.</li>
<li>Folder as a project. I like this concept and you can sorta do this in Coda but it&#8217;s nice to open one project/folder with tabs for all of the files that are part of that project but still be able to open separate windows for other files that I randomly need to edit. If you right-click&#8230;open in Coda, it&#8217;ll create another tab in the &#8220;workspace&#8221; that you are working in even if the file has nothing to do with that project.</li>
</ul>
<p>Cons:</p>
<ul>
<li>None really other than it missing some of the Pros of Coda.</li>
</ul>
<div style="clear:both;">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://maccherone.com/larry/2012/01/02/coda-vs-webstorm-vs-textmate-for-coffeescript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A multiple file loader for Flex/Flash/ActionScript 3 (AS3)</title>
		<link>http://maccherone.com/larry/2009/05/31/a-multiple-file-loader-for-flexflashactionscript-3-as3/</link>
		<comments>http://maccherone.com/larry/2009/05/31/a-multiple-file-loader-for-flexflashactionscript-3-as3/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 01:28:16 +0000</pubDate>
		<dc:creator>Larry Maccherone</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flex/Flash/ActionScript]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://maccherone.com/larry/?p=120</guid>
		<description><![CDATA[The URLMultiLoader class in this library will load multiple files and optionally &#8220;process&#8221; them before calling the method specified for Event.COMPLETE. Since file loading in the Flash/Flex/AS3 world is completely asynchronous, when you need to load more than one file, &#8230; <a href="http://maccherone.com/larry/2009/05/31/a-multiple-file-loader-for-flexflashactionscript-3-as3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><!--S-ButtonZ 1.1.5 Start-->
<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://maccherone.com/larry/2009/05/31/a-multiple-file-loader-for-flexflashactionscript-3-as3/";
		var dzone_title = "A multiple file loader for Flex/Flash/ActionScript 3 (AS3)";
		var dzone_style = "1";
		var dzone_blurb = "The URLMultiLoader class in this library will load multiple files and optionally &#8220;process&#8221; them before calling the method specified for Event.COMPLETE. Since file loading in the Flash/Flex/AS3 world is completely asynchronous, when you need...";
		//-->
		</script><br />
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div>
<p><!--S-ButtonZ 1.1.5 End-->The URLMultiLoader class in this library will load multiple files and optionally &#8220;process&#8221; them before calling the method specified for Event.COMPLETE. Since file loading in the Flash/Flex/AS3 world is completely asynchronous, when you need to load more than one file, the hackish solution is to make the COMPLETE handler for the first one initiate the load for the second, etc. until all the files are loaded. URLMultiLoader will allow you to setup one COMPLETE handler which will not be called until all the files you specify are loaded (and optionally &#8220;processed&#8221;).</p>
<p>When I first had need for this, I said to myself that someone must have done this before. It seems like a fairly common need. <span style="text-decoration: line-through;">However, when I went looking, I couldn&#8217;t find something that fit the bill, so I decided to write my own. </span>It was actually a very good way to get familiar with the event system. Also, while I was at it, I figured I&#8217;d allow the injection of a processor for each file and make sure that got processed before proceeding. <span style="text-decoration: line-through;">If anyone knows of another tool like this please post a link to it in the comments. Actually, it wouldn&#8217;t surprise me if this functionality is built into the Flex framework somewhere and I just missed it.</span></p>
<p>Update: The functionality mustn&#8217;t be in Flex because I have now found several other similar controls:</p>
<ul>
<li><a href="http://www.stimuli.com.br/trane/2007/nov/25/loading-reloaded/">BulkLoader</a></li>
<li><a href="http://code.google.com/p/queueloader-as3/">QueueLoader</a></li>
<li><a href="http://code.google.com/p/ultimateloader/">UltimateLoader</a></li>
</ul>
<p>Mine is relatively simple compared to some of these. BulkLoader seems particularly featureful. It has bandwidth stats and progress indicators. For my loading needs, the sizes were small enough that I wasn&#8217;t worried about progress or bandwidth, but I may update mine to include these features in the future.</p>
<p>One feature that mine has that many do not have is the optional ability to inject in a an IDataProcessor that will pre-process your data before returning it to you.</p>
<p>DataProcessorXMLStringToArray is provided as an example IDataProcessor that can optionally be passed in when adding a new URLRequest to the queue. If provided, an IDataProcessor will convert the raw file string (or binary, or url variables) into some other form before returning. Complete documentation for DataProcessorXMLStringToArray is provided in the ASDoc header for the class but it is offered here primarily as an example. You can easily create your own and inject them when setting up the URLMultiLoader. You just need to follow the IDataProcessor interface which has one method with the following signature:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">function processData(data:*):*</pre></div></div>

<p>Remember, the processor is totally optional. If omitted, URLMultiLoader will simply copy the file contents into it&#8217;s output data field. The type of the data in that case will depend upon the URLLoaderDataFormat: String for TEXT (default), ByteArray for BINARY, and URLVariables for VARIABLES.</p>
<p>Let&#8217;s see it in action.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">maccherone</span>.<span style="color: #006600;">urlmultiloader</span>.<span style="color: #66cc66;">*</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">maccherone</span>.<span style="color: #006600;">json</span>.<span style="color: #006600;">JSON</span>;  <span style="color: #808080; font-style: italic;">// Only used for pretty output</span>
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Bitmap</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Loader</span>;
	<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;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">IOErrorEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoaderDataFormat</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> URLMultiLoaderTest <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> urlMultiLoader:URLMultiLoader = <span style="color: #000000; font-weight: bold;">new</span> URLMultiLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> baseURL:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;data/&quot;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> urlRequest1:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>baseURL + <span style="color: #ff0000;">&quot;file.xml&quot;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> urlRequest2:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>baseURL + <span style="color: #ff0000;">&quot;file.xml&quot;</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #808080; font-style: italic;">// Same file but we'll get it in a different format</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> urlRequest3:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>baseURL + <span style="color: #ff0000;">&quot;smile.gif&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> URLMultiLoaderTest<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> urlMultiLoader:URLMultiLoader = <span style="color: #000000; font-weight: bold;">new</span> URLMultiLoader
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> dataProcessor:IDataProcessor = <span style="color: #000000; font-weight: bold;">new</span> DataProcessorXMLStringToArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #808080; font-style: italic;">// Example provided with URLMultiLoader. You can create your own.</span>
&nbsp;
			urlMultiLoader.<span style="color: #006600;">addURLRequest</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Request1&quot;</span>, urlRequest1, dataProcessor<span style="color: #66cc66;">&#41;</span>
			urlMultiLoader.<span style="color: #006600;">addURLRequest</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Request2&quot;</span>, urlRequest2<span style="color: #66cc66;">&#41;</span>  <span style="color: #808080; font-style: italic;">// If no IDataProcessor is provided, then file's contents is returned as String, ByteArray, or</span>
			                                           <span style="color: #808080; font-style: italic;">// URLVariables depending upon the URLLoaderDataFormat TEXT, BINARY, or VARIABLES respectively</span>
			urlMultiLoader.<span style="color: #006600;">addURLRequest</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Request3&quot;</span>, urlRequest3, <span style="color: #000000; font-weight: bold;">null</span>, URLLoaderDataFormat.<span style="color: #006600;">BINARY</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #808080; font-style: italic;">// Loads smile.gif as a ByteArray</span>
&nbsp;
			urlMultiLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, filesLoaded<span style="color: #66cc66;">&#41;</span>
			urlMultiLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>IOErrorEvent.<span style="color: #006600;">IO_ERROR</span>, onError<span style="color: #66cc66;">&#41;</span>
			urlMultiLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> filesLoaded<span style="color: #66cc66;">&#40;</span>event:Event<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> <span style="color: #0066CC;">data</span>:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span> as URLMultiLoader<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">data</span>
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Array of Objects:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> + JSON.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Request1&quot;</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// Uses JSON.encode for pretty output</span>
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;String of file contents:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> + <span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Request2&quot;</span><span style="color: #66cc66;">&#93;</span> + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			loader.<span style="color: #006600;">loadBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Request3&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>loader<span style="color: #66cc66;">&#41;</span>  <span style="color: #808080; font-style: italic;">// Displays smile.gif in Flash player</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onError<span style="color: #66cc66;">&#40;</span>event:Event<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>event<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></div></div>

<p>Assuming you put the file.xml and the smile.gif , in a data/ folder below the bin-debug directory and you have the correct security settings, the above code would result in the following output:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Array of Objects:
[
    {&quot;id&quot;: 101, &quot;name&quot;: &quot;/db/node/visitor&quot;},
    {&quot;id&quot;: 102, &quot;name&quot;: &quot;/db/node/observer&quot;},
    {&quot;id&quot;: 103, &quot;name&quot;: &quot;/ui/button&quot;}
]
&nbsp;
String of file contents:
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;root&gt;
  &lt;file&gt;
    &lt;id&gt;101&lt;/id&gt;
    &lt;name&gt;/db/node/visitor&lt;/name&gt;
  &lt;/file&gt;
  &lt;file&gt;
    &lt;id&gt;102&lt;/id&gt;
    &lt;name&gt;/db/node/observer&lt;/name&gt;
  &lt;/file&gt;
  &lt;file&gt;
    &lt;id&gt;103&lt;/id&gt;
    &lt;name&gt;/ui/button&lt;/name&gt;
  &lt;/file&gt;
&lt;/root&gt;</pre></div></div>

<p>Plus it will display smile.gif in the Flash player like this:</p>
<p><img class="alignnone size-full wp-image-127" title="smile_in_flash_player" src="http://maccherone.com/larry/wp-content/uploads/2009/05/smile_in_flash_player.png" alt="smile_in_flash_player" width="290" height="251" /></p>
<p>You can download it from <a href="http://maccherone.com/larry/projects/a-multiple-file-loader-for-flashflex-in-actionscript-3-as3/">here</a>.</p>
<p>Update: I altered the URLMultiLoader to use a string as the key to retrieving the data after the loading is complete. A previous version used the URLRequest as the key for Dictionary object. This version does not depend upon Dictionary.
<div style="clear:both;">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://maccherone.com/larry/2009/05/31/a-multiple-file-loader-for-flexflashactionscript-3-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActionScript 3 (AS3) JSON encoder with &#8220;pretty&#8221; output by adding linefeeds and spaces</title>
		<link>http://maccherone.com/larry/2009/05/28/actionscript-3-as3-json-encoder-with-pretty-output-by-adding-linefeeds-and-spaces/</link>
		<comments>http://maccherone.com/larry/2009/05/28/actionscript-3-as3-json-encoder-with-pretty-output-by-adding-linefeeds-and-spaces/#comments</comments>
		<pubDate>Fri, 29 May 2009 02:50:51 +0000</pubDate>
		<dc:creator>Larry Maccherone</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flex/Flash/ActionScript]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://maccherone.com/larry/?p=65</guid>
		<description><![CDATA[I&#8217;m sure many ActionScript 3 or Flex developers have used the as3corelib for one reason or another. It&#8217;s a wonderful little library with lots of useful functionality. I&#8217;ve frequently used its JSON  encoding and decoding functionality. It works great, however, &#8230; <a href="http://maccherone.com/larry/2009/05/28/actionscript-3-as3-json-encoder-with-pretty-output-by-adding-linefeeds-and-spaces/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><!--S-ButtonZ 1.1.5 Start-->
<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://maccherone.com/larry/2009/05/28/actionscript-3-as3-json-encoder-with-pretty-output-by-adding-linefeeds-and-spaces/";
		var dzone_title = "ActionScript 3 (AS3) JSON encoder with &#8220;pretty&#8221; output by adding linefeeds and spaces";
		var dzone_style = "1";
		var dzone_blurb = "I&#8217;m sure many ActionScript 3 or Flex developers have used the as3corelib for one reason or another. It&#8217;s a wonderful little library with lots of useful functionality. I&#8217;ve frequently used its JSON  encoding and decoding functionality....";
		//-->
		</script><br />
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div>
<p><!--S-ButtonZ 1.1.5 End-->I&#8217;m sure many ActionScript 3 or Flex developers have used the <a href="http://code.google.com/p/as3corelib/" target="_blank">as3corelib</a> for one reason or another. It&#8217;s a wonderful little library with lots of useful functionality. I&#8217;ve frequently used its JSON  encoding and decoding functionality. It works great, however, it doesn&#8217;t add spaces or linefeeds to make the resulting JSON string more readable. That&#8217;s fine if you are just serializing something to send over the wire but not if you want it to render something that is easily read by a human. In my case, I want a user to actually be able to edit the resulting JSON. To make this workable, I needed a JSON encoder that would add appropriate linefeeds and spaces. Rather than write my own, I simply adapted the one in as3corelib.</p>
<p>One side benefit of having done this is that you can now get JSON serialization without getting the entire as3corelib library.</p>
<p>The default interface is identical to the one in as3corelib. If you just call JSON.encode(my_object), it will behave <span style="text-decoration: line-through;">almost </span>exactly like the one in as3corelib. <span style="text-decoration: line-through;">I say &#8220;almost&#8221; because my version add a space after each &#8220;:&#8221; and &#8220;,&#8221; even in default mode.</span> <strong>Update</strong>: I&#8217;ve changed it so it behaves exactly like the serializer in as3corelib so no extra spaces are added unless you use the optional parameters described below.</p>
<p>If you want linefeeds and truly &#8220;pretty&#8221; output, you can add an optional second parameter, like so JSON.encode(my_object, true). This will cause any array [ ] or object { } that would be longer than 60 characters to wrap to newlines, which works out about right for my purposes.</p>
<p>You can also adjust the maximum line length with an optional third parameter, like this JSON.encode(my_object, true, 10). This will cause any line above 10 to wrap. If you want every array [ ] and object { } to wrap, just use any number 2 or lower in this third parameter. If you want it to wrap everything but empty objects or arrays, use 3 for this parameter.</p>
<p>Let&#8217;s see it in action.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">maccherone</span>.<span style="color: #006600;">json</span>.<span style="color: #006600;">JSON</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;    
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Tester <span style="color: #0066CC;">extends</span> Sprite
    <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Tester<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> obj1:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>
                commit: <span style="color: #66cc66;">&#123;</span>file: <span style="color: #ff0000;">&quot;commit.xml&quot;</span><span style="color: #66cc66;">&#125;</span>,
                commit_detail: <span style="color: #66cc66;">&#123;</span>file: <span style="color: #ff0000;">&quot;commit_detail.xml&quot;</span><span style="color: #66cc66;">&#125;</span>,
                file: <span style="color: #66cc66;">&#123;</span>file: <span style="color: #ff0000;">&quot;file.xml&quot;</span><span style="color: #66cc66;">&#125;</span>,
                person: <span style="color: #66cc66;">&#123;</span>file: <span style="color: #ff0000;">&quot;person.xml&quot;</span><span style="color: #66cc66;">&#125;</span>,
                count: <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span>
            <span style="color: #66cc66;">&#125;</span>
            <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Just like as3corelib (no line feeds or spaces):<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> + JSON.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>obj1<span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'&quot;Smart&quot; linefeeds:<span style="color: #000099; font-weight: bold;">\n</span>'</span> + JSON.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>obj1, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Only allow short lines:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> + JSON.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>obj1, <span style="color: #000000; font-weight: bold;">true</span>, <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #000000; font-weight: bold;">var</span> obj2:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>
                <span style="color: #ff0000;">&quot;glossary&quot;</span>: <span style="color: #66cc66;">&#123;</span>
                    <span style="color: #ff0000;">&quot;title&quot;</span>: <span style="color: #ff0000;">&quot;example glossary&quot;</span>,
                    <span style="color: #ff0000;">&quot;GlossDiv&quot;</span>: <span style="color: #66cc66;">&#123;</span>
                        <span style="color: #ff0000;">&quot;title&quot;</span>: <span style="color: #ff0000;">&quot;S&quot;</span>,
                        <span style="color: #ff0000;">&quot;GlossList&quot;</span>: <span style="color: #66cc66;">&#123;</span>
                            <span style="color: #ff0000;">&quot;GlossEntry&quot;</span>: <span style="color: #66cc66;">&#123;</span>
                                <span style="color: #ff0000;">&quot;ID&quot;</span>: <span style="color: #ff0000;">&quot;SGML&quot;</span>,
                                <span style="color: #ff0000;">&quot;SortAs&quot;</span>: <span style="color: #ff0000;">&quot;SGML&quot;</span>,
                                <span style="color: #ff0000;">&quot;GlossTerm&quot;</span>: <span style="color: #ff0000;">&quot;Standard Generalized Markup Language&quot;</span>,
                                <span style="color: #ff0000;">&quot;Acronym&quot;</span>: <span style="color: #ff0000;">&quot;SGML&quot;</span>,
                                <span style="color: #ff0000;">&quot;Abbrev&quot;</span>: <span style="color: #ff0000;">&quot;ISO 8879:1986&quot;</span>,
                                <span style="color: #ff0000;">&quot;GlossDef&quot;</span>: <span style="color: #66cc66;">&#123;</span>
                                    <span style="color: #ff0000;">&quot;para&quot;</span>: <span style="color: #ff0000;">&quot;A meta-markup language, used to create markup languages such as DocBook.&quot;</span>,
                                    <span style="color: #ff0000;">&quot;GlossSeeAlso&quot;</span>: <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;GML&quot;</span>, <span style="color: #ff0000;">&quot;XML&quot;</span><span style="color: #66cc66;">&#93;</span>
                                <span style="color: #66cc66;">&#125;</span>,
                                <span style="color: #ff0000;">&quot;GlossSee&quot;</span>: <span style="color: #ff0000;">&quot;markup&quot;</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>
            <span style="color: #66cc66;">&#125;</span>
            <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;A bigger example from JSON.org:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> + JSON.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>obj2, <span style="color: #000000; font-weight: bold;">true</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></div></div>

<p>The above code would result in the following output:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Just like as3corelib (no line feeds or spaces):
{&quot;file&quot;:{&quot;file&quot;:&quot;file.xml&quot;},&quot;commit&quot;:{&quot;file&quot;:&quot;commit.xml&quot;},&quot;commit_detail&quot;:{&quot;file&quot;:&quot;commit_detail.xml&quot;},&quot;person&quot;:{&quot;file&quot;:&quot;person.xml&quot;},&quot;count&quot;:[1,2,3]}
&nbsp;
&quot;Smart&quot; linefeeds:
{
    &quot;file&quot;: {&quot;file&quot;: &quot;file.xml&quot;},
    &quot;commit&quot;: {&quot;file&quot;: &quot;commit.xml&quot;},
    &quot;commit_detail&quot;: {&quot;file&quot;: &quot;commit_detail.xml&quot;},
    &quot;person&quot;: {&quot;file&quot;: &quot;person.xml&quot;},
    &quot;count&quot;: [1, 2, 3]
}
&nbsp;
Only allow short lines:
{
    &quot;file&quot;: {
        &quot;file&quot;: &quot;file.xml&quot;
    },
    &quot;commit&quot;: {
        &quot;file&quot;: &quot;commit.xml&quot;
    },
    &quot;commit_detail&quot;: {
        &quot;file&quot;: &quot;commit_detail.xml&quot;
    },
    &quot;person&quot;: {
        &quot;file&quot;: &quot;person.xml&quot;
    },
    &quot;count&quot;: [1, 2, 3]
}
&nbsp;
A bigger example from JSON.org:
{
    &quot;glossary&quot;: {
        &quot;GlossDiv&quot;: {
            &quot;GlossList&quot;: {
                &quot;GlossEntry&quot;: {
                    &quot;GlossSee&quot;: &quot;markup&quot;,
                    &quot;GlossTerm&quot;: &quot;Standard Generalized Markup Language&quot;,
                    &quot;ID&quot;: &quot;SGML&quot;,
                    &quot;GlossDef&quot;: {
                        &quot;para&quot;: &quot;A meta-markup language, used to create markup languages such as DocBook.&quot;,
                        &quot;GlossSeeAlso&quot;: [&quot;GML&quot;, &quot;XML&quot;]
                    },
                    &quot;Abbrev&quot;: &quot;ISO 8879:1986&quot;,
                    &quot;Acronym&quot;: &quot;SGML&quot;,
                    &quot;SortAs&quot;: &quot;SGML&quot;
                }
            },
            &quot;title&quot;: &quot;S&quot;
        },
        &quot;title&quot;: &quot;example glossary&quot;
    }
}</pre></div></div>

<p>Note that (unlike XML) the order of the elements in a JSON object { } is indeterminant. Of course the order of an array [ ] is preserved.</p>
<p>You can download it from <a href="http://maccherone.com/larry/projects/a-pretty-json-encoder-for-actionscript-3-as3/">here</a>.
<div style="clear:both;">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://maccherone.com/larry/2009/05/28/actionscript-3-as3-json-encoder-with-pretty-output-by-adding-linefeeds-and-spaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

