<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[The Programming Blog of Andreas Renberg (IQAndreas)]]></title>
  <link href="http://blog.iqandreas.com/atom.xml" rel="self"/>
  <link href="http://blog.iqandreas.com/"/>
  <updated>2014-05-09T01:24:48-05:00</updated>
  <id>http://blog.iqandreas.com/</id>
  <author>
    <name><![CDATA[Andreas Renberg (IQAndreas)]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[What Are the Default Permissions for Files in Ubuntu?]]></title>
    <link href="http://blog.iqandreas.com/ubuntu/what-are-the-default-permissions-for-files-in-ubuntu/"/>
    <updated>2013-11-17T10:54:00-06:00</updated>
    <id>http://blog.iqandreas.com/ubuntu/what-are-the-default-permissions-for-files-in-ubuntu</id>
    <content type="html"><![CDATA[<p><em><strong>TL;DR version:</strong> Skip to <a href="http://blog.iqandreas.com/ubuntu/what-are-the-default-permissions-for-files-in-ubuntu/#summary">In a nutshell</a>.</em></p>

<p><em>This article assumes you understand the notiation for file system permissions, and have a basic grasp on the topic. If not, there is a nice starter article on the Ubuntu community wiki:</em></p>

<p><li class="flink com ubuntu_com help_ubuntu_com"><a href="https://help.ubuntu.com/community/FilePermissions">Ubuntu: Understanding and using File Permissions</a></li></p>

<p>By default, when you create a file in Ubuntu as a standard user (either in Nautilus or with <code>touch</code>), it gets the permission of <code>644</code>. If you mark that file as executable, as expected, it gets the permission <code>755</code>.</p>

<p>What may be surprising is that directories also have a default permission of <code>755</code>. Even though it seems like directories aren&rsquo;t the type of thing that would be &ldquo;executed&rdquo;, this flag is actually very important to Linux! <!-- more -->(and if anyone can find an article behind the reasoning behind this decision, I would love to find out)</p>

<p>If a directory (or <em>any</em> of its parent directories) isn&rsquo;t marked as executable, you cannot <code>cd</code> into it. Although it is browsable in Nautilus, trying to write anything to the folder results in a &ldquo;forbidden&rdquo; or &ldquo;insufficient privileges&rdquo; error message. Some commands (like <code>ls</code>) work on the directory, while others (such as <code>stat</code>) do not.</p>

<p>Links (both to files and directories) have the permission <code>777</code>, which I&rsquo;m assuming is done for the similar reasons as the executable bit on directories.</p>

<h3>On external media</h3>

<p>For external harddrives, USB drives, or SD cards that are mounted in <code>/media/&lt;username&gt;</code>, if you haven&rsquo;t manually changed either the mount settings or file system format of the drive, the file system type is likely to be either <code>Fat32</code> or <code>NTFS</code>. Here, the file permissions are going to be different, with a value of <code>600</code> for files and <code>700</code> for directories. Links remain the same at <code>777</code>, though it is unclear to me if links created in Linux are stored differently or not on foreign file systems.</p>

<p>As far as I can tell, there is no way to change file and directory permissions, or even mark files as being executable without changing the mount settings, so all files are always stuck with a privilege of <code>600</code>. This makes sense as such file systems don&rsquo;t use the same type of permission settings for files, so storing the permission data would be difficult. In fact, I&rsquo;m just glad we are able read from and write to those types of file systems from Linux at all!</p>

<h3><a name="summary"></a>In a nutshell</h3>

<p>These are the default values for file permissions in Ubuntu 13.10. They may be the same in other Linux distributions, but I have not been able to verify this personally.</p>

<p><strong>In a standard ext3 file system</strong></p>

<ul>
<li><code>644</code> files</li>
<li><code>755</code> executable files</li>
<li><code>755</code> directories</li>
<li><code>777</code> links to files</li>
<li><code>777</code> links to directories</li>
</ul>


<p><strong>For removable media (Fat32) and windows partitions (NTFS)</strong></p>

<ul>
<li><code>600</code> files (can&rsquo;t be executable)</li>
<li><code>700</code> directories</li>
<li><code>777</code> links to files</li>
<li><code>777</code> links to directories</li>
</ul>


<h3>A script for better displaying file permissions in a directory</h3>

<p>While you can display the permissions of files in a directory with <code>ls -l</code>, that information isn&rsquo;t very easy to read:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class=''><span class='line'> $ ls -l
</span><span class='line'>total 16
</span><span class='line'>drwxr-xr-x 2 andreas andreas 4096 Nov 17 11:00 cat-images-folder
</span><span class='line'>-rw-r--r-- 1 andreas andreas  245 Nov 17 10:58 cat-images.zip
</span><span class='line'>-rwxr-xr-x 1 andreas andreas   30 Nov 17 11:15 do-something.sh
</span><span class='line'>lrwxrwxrwx 1 andreas andreas   56 Nov 17 11:23 Link to cat-images-folder -&gt; /home/andreas/temp/cat-images-folder
</span><span class='line'>lrwxrwxrwx 1 andreas andreas   53 Nov 17 11:22 Link to cat-images.zip -&gt; /home/andreas/temp/cat-images.zip
</span><span class='line'>-rw-r--r-- 1 andreas andreas 1922 Nov 17 11:15 readme.txt</span></code></pre></td></tr></table></div></figure>


<p>Instead, you can instead use the <code>stat</code> command to display permissions in the more friendly &ldquo;octal notation&rdquo; (<a href="http://thenubbyadmin.com/2012/02/16/how-to-list-linux-file-permissions-in-octal-notation/">source</a>):</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class=''><span class='line'> $ stat -c "%a %n" *
</span><span class='line'>755 cat-images-folder
</span><span class='line'>644 cat-images.zip
</span><span class='line'>755 do-something.sh
</span><span class='line'>777 Link to cat-images-folder
</span><span class='line'>777 Link to cat-images.zip
</span><span class='line'>644 readme.txt</span></code></pre></td></tr></table></div></figure>


<p>And if you want to tweak the output further (such as to tell us whether an item is a file, directory, or link), see the following page (or just run <code>man stat</code>) which lists all available options:</p>

<p><li class="flink com ubuntu_com manpages_ubuntu_com"><a href="http://manpages.ubuntu.com/manpages/precise/en/man1/stat.1.html">Ubuntu manuals: stat</a></li></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[GIT: How to Move Tags]]></title>
    <link href="http://blog.iqandreas.com/git/how-to-move-tags/"/>
    <updated>2013-11-17T06:43:00-06:00</updated>
    <id>http://blog.iqandreas.com/git/how-to-move-tags</id>
    <content type="html"><![CDATA[<p>Say you already added a tag, but later realized that it was in the wrong place, or perhaps you needed to add a few more last-minute commits. How would you go about moving it?<!-- more --></p>

<p><strong>Unrelated but important side note:</strong> Since you are tagging in Git, <a href="http://www.rockstarprogrammer.org/post/2008/oct/16/git-tag-does-wrong-thing-default/">you are using the <code>-a</code> flag, right?</a></p>

<h3>Editing the tag locally</h3>

<p>You could <span class="hoverable" title="git tag -d &lt;tag_name&gt;">delete it</span> and <span class="hoverable" title="git tag -a &lt;tag_name&gt;">re-add it</span>, but all the hard work you put into writing the tag&rsquo;s description would be lost.</p>

<p>Instead, choose the place in your history where you want the tag moved to, tag it like you usually would, but add <code>-f</code> (or <code>--force</code>) to the command; that extra flag will allow you to replace the other tag with the same name. And a pleasant surprise appears if we try to overwrite an existing tag:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'> $ git tag -a v2.56 8bad64f6e9 -f</span></code></pre></td></tr></table></div></figure>


<p><img src="http://blog.iqandreas.com/images/blog/git-terminal-window-overwrite-existing-tag.small.png" title="&#34;Terminal window in Ubuntu editing a GIT tag&#34;" alt="&#34;Terminal window in Ubuntu editing a GIT tag&#34;"></p>

<p><em>Hey! That&rsquo;s my old tag description!</em> Now you can edit it if you want, or just save it as the way it was.</p>

<h3>Editing the tag on the server</h3>

<p>If you have already pushed the tag to the server and want to fix that, first make sure your local version of the tag is correct. Then all you need to do is make another <code>push</code> using the same <code>-f</code> (or <code>--force</code>) flag.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'> $ git push origin --tags -f</span></code></pre></td></tr></table></div></figure>


<p>Remember to alert any other developers on the team if you ever &ldquo;force&rdquo; a change like this. If they still have an &ldquo;old&rdquo; version of the tag around, it may cause conflicts when they try to push to the server!</p>

<h3>If the tag is edited on the server, but the local one is old</h3>

<p>Say <em>someone else</em> moved a tag, but the version in your local repository still points to the old commit? First, delete the local tag, then pull in the changes from the remote repo; the new tag will be added automatically.</p>

<p>So, for example (in my case, the tag name is <code>v2.56</code> and the remote repository is named <code>origin</code>):</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'> $ git tag -d v2.56
</span><span class='line'>Deleted tag 'v2.56' (was 75ff2f1)
</span><span class='line'> $ git fetch origin --tags
</span><span class='line'>From https://github.com/FlixelCommunity/flixel
</span><span class='line'> * [new tag]         v2.56      -&gt; v2.56</span></code></pre></td></tr></table></div></figure>


<p>In this example, the <code>--tags</code> flag was actually optional, since <code>git fetch</code> will by default automatically fetch tags along with any modified branches. But there is no harm leaving it in there for clarity.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[GIT: Storing HTTPS Authentication in Ubuntu (and Arch Linux)]]></title>
    <link href="http://blog.iqandreas.com/git/storing-https-authentication-in-ubuntu-and-arch-linux/"/>
    <updated>2013-10-24T03:48:00-05:00</updated>
    <id>http://blog.iqandreas.com/git/storing-https-authentication-in-ubuntu-and-arch-linux</id>
    <content type="html"><![CDATA[<p><em><strong>TL;DR version:</strong> Skip to <a href="http://blog.iqandreas.com/git/storing-https-authentication-in-ubuntu-and-arch-linux/#storing-your-https-credentials-using-a-keyring">Storing your HTTPS credentials using a Keyring</a>.</em></p>

<p>If you use GIT in Ubuntu, you may be used to this seeing this several times a day:</p>

<p><img src="http://blog.iqandreas.com/images/blog/git-terminal-window-in-ubuntu.small.png" title="&#34;Terminal window in Ubuntu asking for GIT credentials&#34;" alt="&#34;Terminal window in Ubuntu asking for GIT credentials&#34;"></p>

<p>Tired of constantly typing typing in your credentials? (especially since GitHub requires an alpha-numerical password, so your standard, &ldquo;easy-to-type&rdquo; one won&rsquo;t do)<!-- more --></p>

<h3>If you can use SSH, use it</h3>

<p>SSH is more secure (and although I have not confirmed this officially, it seems to transfer faster than HTTPS). If it is <em>at all</em> possible, use SSH instead of HTTPS. <em>I would be using SSH myself if it wasn&rsquo;t for a known bug in the modem required by my ISP which constantly drops the connection mid-transfer; Damn you Telia!</em></p>

<p>When using SSH, you only have to &ldquo;generate&rdquo; a key once for every computer you use, store it in the appropriate directory, and every time you connect to GitHub, that key will be used automatically:</p>

<p><li class="flink com github_com help_github_com"><a href="https://help.github.com/articles/generating-ssh-keys">GitHub Help: Generating SSH Keys</a></li></p>

<h4>If the SSH port is being blocked</h4>

<p>If it&rsquo;s just an issue of blocked ports, GitHub does provide a service for creating an SSH connection (usually <code>port 22</code>) through the HTTPS port (<code>port 443</code>) which may get past most firewalls. I&rsquo;m unsure if this is preferable to connecting over HTTPS or not, but at least the option is available:</p>

<p><li class="flink com github_com help_github_com"><a href="https://help.github.com/articles/using-ssh-over-the-https-port">GitHub Help: Using SSH over the HTTPS port</a></li></p>

<h3><a name="storing-your-https-credentials-using-a-keyring"></a>Storing your HTTPS credentials using a Keyring</h3>

<p><em>SIDE NOTE:</em> There are a lot of old solutions circling the interwebs involving either setting <code>credential.helper</code> to <code>store</code>, or by using <code>netrc</code>, however, in both of these cases the password gets stored as plain-text on your computer. This is usually not ideal.</p>

<p>Instead, you can use <code>gnome-keyring</code> to store your credentials more securely (<a href="http://stackoverflow.com/a/14528360/617937">thanks to James Ward and marcosdsanchez</a> for this solution). <em>This solution assumes you are using GIT 1.8.0 or newer, which if you installed it via <code>apt</code>, you are. If not, you can find the latest version of git from the following URL:</em></p>

<p><li class="flink com git-scm_com"><a href="http://git-scm.com/downloads">Git: Downloads</a></li></p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>sudo apt-get install libgnome-keyring-dev
</span><span class='line'><span class="nv">$ </span>sudo make --directory<span class="o">=</span>/usr/share/doc/git/contrib/credential/gnome-keyring
</span><span class='line'><span class="nv">$ </span>git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
</span></code></pre></td></tr></table></div></figure>


<p>If you are using Arch Linux, you will require <a href="http://stackoverflow.com/a/13390889/617937">a slightly different command</a>, and if you are using OS-X or Windows, GitHub has provided a short set of instructions to use the same GIT feature:</p>

<p><li class="flink com github_com"><a href="https://github.com/blog/1104-credential-caching-for-wrist-friendly-git-usage">GitHub Blog: Credential Caching for Wrist-Friendly Git Usage</a></li></p>

<p>After typing in your user-name and password once the next time you are prompted for it, the credentials should be stored, saving you a lot of typing in the future. If that worked, you are done.</p>

<h3>But if you are a real stickler for security</h3>

<p>If you <em>really</em> want to require entering your password when connecting to GitHub (perhaps you are dealing with security software and want to avoid any loopholes) but are just tired of typing it in all day, you can configure GIT to store your password for a limited amount of time.</p>

<p>By default, GitHub will store your credentials for 15 minutes. If you want to increase or decrease this amount, use the following command:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'> <span class="nv">$ </span>git config --global credential.helper <span class="s2">&quot;cache --timeout=900&quot;</span>
</span></code></pre></td></tr></table></div></figure>


<p>Replace <code>900</code> with <a href="https://www.google.com/#q=15+minutes+to+seconds">the amount of seconds you want the credentials to be saved</a>. Personally, I would recommend 5 hours (<code>18000</code> seconds) if you work in an office, and 12 hours (<code>43200</code> seconds) if you work from home. If you don&rsquo;t want this setting to apply for all your repositories but only for the current repository, remove the <code>--global</code> flag.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why My One Line if Statements Are Unusual]]></title>
    <link href="http://blog.iqandreas.com/actionscript/why-my-one-line-if-statements-are-unusual/"/>
    <updated>2013-01-04T13:02:00-06:00</updated>
    <id>http://blog.iqandreas.com/actionscript/why-my-one-line-if-statements-are-unusual</id>
    <content type="html"><![CDATA[<p>My one line if statements have been described as <em>&ldquo;um&hellip; unique&rdquo;</em> and <em>&ldquo;making me cringe&rdquo;</em>, but trust me, there is method to this madness; mainly, it&rsquo;s practical for debugging.<!-- more --> The sample code is in ActionScript, but should be self-explanatory in any language with similar semantics:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="k">if</span> <span class="o">((</span><span class="n">data</span><span class="o">.</span><span class="na">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="n">server</span><span class="o">.</span><span class="na">enabled</span><span class="o">)</span>
</span><span class='line'>  <span class="o">{</span> <span class="n">server</span><span class="o">.</span><span class="na">send</span><span class="o">(</span><span class="n">data</span><span class="o">);</span> <span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<p><em>The average developer</em> doesn&rsquo;t include those extra braces on the second line, and in fact, many will even keep everything on one single line. (You could also pull the braces down so the block of code occupies a full 4 lines of code, but that seems highly unnecessary.)</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="k">if</span> <span class="o">((</span><span class="n">data</span><span class="o">.</span><span class="na">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="n">server</span><span class="o">.</span><span class="na">enabled</span><span class="o">)</span> <span class="n">server</span><span class="o">.</span><span class="na">send</span><span class="o">(</span><span class="n">data</span><span class="o">);</span>
</span></code></pre></td></tr></table></div></figure>


<p>The reason I add these otherwise unnecessary braces is primarily for debugging. Say in our sample code, the data isn&rsquo;t arriving at the server; a good developer goes back to make sure the data is being sent in the first place. The following function <em>looks</em> correct (and as a side note should work in a white-space oriented language such as Python), but does not function as expected:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="k">if</span> <span class="o">((</span><span class="n">data</span><span class="o">.</span><span class="na">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="n">server</span><span class="o">.</span><span class="na">enabled</span><span class="o">)</span>
</span><span class='line'>  <span class="n">server</span><span class="o">.</span><span class="na">send</span><span class="o">(</span><span class="n">data</span><span class="o">);</span> <span class="nf">trace</span><span class="o">(</span><span class="s2">&quot;Data sent&quot;</span><span class="o">);</span>
</span><span class='line'>  
</span><span class='line'><span class="c1">// or even</span>
</span><span class='line'><span class="k">if</span> <span class="o">((</span><span class="n">data</span><span class="o">.</span><span class="na">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="n">server</span><span class="o">.</span><span class="na">enabled</span><span class="o">)</span>
</span><span class='line'>  <span class="n">server</span><span class="o">.</span><span class="na">send</span><span class="o">(</span><span class="n">data</span><span class="o">);</span>
</span><span class='line'>  <span class="nf">trace</span><span class="o">(</span><span class="s2">&quot;Data sent&quot;</span><span class="o">);</span>
</span><span class='line'>  
</span><span class='line'><span class="c1">// But my personal preference allows for the additional code:</span>
</span><span class='line'><span class="k">if</span> <span class="o">((</span><span class="n">data</span><span class="o">.</span><span class="na">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="o">)</span> <span class="o">&amp;&amp;</span> <span class="n">server</span><span class="o">.</span><span class="na">enabled</span><span class="o">)</span>
</span><span class='line'>  <span class="o">{</span> <span class="n">server</span><span class="o">.</span><span class="na">send</span><span class="o">(</span><span class="n">data</span><span class="o">);</span> <span class="nf">trace</span><span class="o">(</span><span class="s2">&quot;Data sent&quot;</span><span class="o">);</span> <span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>A good developer is smart enough to add the required brackets when adding the &ldquo;debugging code&rdquo;. I prefer adding the brackets preemptively; the extra time it takes to wrap the code in brackets isn&rsquo;t that valuable to me.</p>

<p><em>(I also have a personal philosophy that <code>if</code>, <code>for</code>, <code>do</code>, and <code>while</code> should always be followed by an open bracket containing code rather than just code on its own, but that just has to do with the way I view the language as functioning behind the scenes. But it&rsquo;s more difficult convincing other developers based on those grounds.)</em></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Best Practices for Git Ignore]]></title>
    <link href="http://blog.iqandreas.com/git/best-practices-for-git-ignore/"/>
    <updated>2013-01-02T11:46:00-06:00</updated>
    <id>http://blog.iqandreas.com/git/best-practices-for-git-ignore</id>
    <content type="html"><![CDATA[<p>The <a href="http://www.kernel.org/pub/software/scm/git/docs/">man pages for GIT</a> aren&rsquo;t usually the clearest or most helpful, and is seldom the first place I turn to for help. Still, I ran across some valuable &ldquo;best practices&rdquo; information which I myself have not been following due to ignorance.<!-- more --></p>

<p>I thought the only place to mark which files to hide was inside of a <code>.gitignore</code> file, ideally placed at the root of the repository. As a result, I would list all files and folders I may want to ignore inside of it. [<a href="https://github.com/FlixelCommunity/flixel/blob/dev/.gitignore">1</a>]</p>

<p>Instead, GIT has provided us with four places to provide <a href="http://www.kernel.org/pub/software/scm/git/docs/gitignore.html#_pattern_format"><em>file name patterns</em></a>, each with its own intended purpose <em>(some descriptions have been taken verbatim from the docs)</em>:</p>

<ul>
<li><p><strong>Sent as command line arguments</strong> <em>(Only supported by some commands)</em> &ndash; Mostly only useful for scripts or &ldquo;temporary exceptions&rdquo;.</p></li>
<li><p><strong>A .gitignore file in the project directory</strong> &ndash; Patterns which should be version-controlled and distributed to other repositories via clone (i.e., files that <em>all</em> developers will want to ignore)</p></li>
<li><p><strong>In the file .git/info/exclude</strong> &ndash; Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user&rsquo;s workflow)</p></li>
<li><p><strong>In the configuration variable core.excludesfile</strong> &ndash; Patterns which a user wants GIT to ignore in <em>all</em> situations (e.g., backup or temporary files generated by the user’s editor of choice). Note that you can set the <a href="http://stackoverflow.com/questions/2114111/where-does-git-config-global-get-written-to">global config value</a>, so every single project you work on will always ignore those pesky files such as <code>Thumbs.db</code>.</p></li>
</ul>


<p>There are also further technical details in which ignores take precedence etc. in case anyone wants some heavier reading:</p>

<p><li class="flink org kernel_org www_kernel_org"><a href="http://www.kernel.org/pub/software/scm/git/docs/gitignore.html">GIT Docs: gitignore Manual Page</a></li></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[How to Ignore the Constructor When Extending a Class]]></title>
    <link href="http://blog.iqandreas.com/actionscript/how-to-ignore-the-constructor-when-extending-a-class/"/>
    <updated>2012-06-13T08:47:00-05:00</updated>
    <id>http://blog.iqandreas.com/actionscript/how-to-ignore-the-constructor-when-extending-a-class</id>
    <content type="html"><![CDATA[<p>As we all know, if you don&rsquo;t call <code>super()</code> in your constructor&rsquo;s code, the Flash compiler will automatically append it to your constructor&rsquo;s code.</p>

<p>Turns out, this isn&rsquo;t entirely true. The compiler only adds <code>super()</code> if it doesn&rsquo;t see it written out in the constructor. It makes no distinction whether you actually call it or not. Here is a simple little trick if you want to completely hop over calling <code>super()</code> when creating a sub-class.<!-- more --></p>

<div><script src='https://gist.github.com/2922489.js'></script>
<noscript><pre><code>class Subclass extends Base 
{
    public function Subclass()
    {
        if (false)
        {
            super();
        }
    }
}</code></pre></noscript></div>


<p>If you want more reading on the matter, this information was taken from a forum thread by <a href="http://me.reclipse.net/">Krilnon</a> over at the Kirupa forums.</p>

<ul>
<li><a href="http://www.kirupa.com/forum/showthread.php?363399-Tip-Skipping-super%28%29-Interesting-behavior"><img class="favicon" src="http://www.kirupa.com/favicon.ico"> [TIP] Skipping super() &ndash; Interesting behavior</a></li>
</ul>


<p>But remember, as I brought up in the forum thread linked to above:</p>

<blockquote><p>In my opinion, this is pure evil! No good can come of not calling constructors, none at all&#8230;</p></blockquote>


<p>So use with caution!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Pick a Community, Any Community]]></title>
    <link href="http://blog.iqandreas.com/monologues/pick-a-community-any-community/"/>
    <updated>2012-06-12T09:56:00-05:00</updated>
    <id>http://blog.iqandreas.com/monologues/pick-a-community-any-community</id>
    <content type="html"><![CDATA[<p><span class='pullquote-right' data-pullquote='Learning to program all on your own can be hard, really hard in fact.'>Learning to program all on your own can be hard, really hard in fact. Sometimes it helps having a place where you can ask questions when Google just isn&rsquo;t giving you what you are looking for. There are also benefits in using a community to <em>answer</em> programming questions (a topic I will cover in an upcoming blog post).</span></p>

<p>To assist in choosing a community, I have compiled a list containing details about various communities and my experience in using them.<!-- more --> As I haven&rsquo;t been to every community out there, I would appreciate if you leave your own recommendations and detailed experiences as a comment below.</p>

<p>The list only contains ActionScript communities, but some of them cover other programming languages or topics as well. But remember, if you want to ask a question on a specific topic, you will get much better results asking in a community that specializes in that topic.</p>

<p>For instance, if you had a Java question, you could ask it on the Kirupa forums in the <a href="http://www.kirupa.com/forum/forumdisplay.php?137-Other-%28Java-C-C-etc-%29">Other (Java, C, C++, etc.)</a> section, but I recommend tracking down a forum with its main focus on Java. Similarly, Box2D and Flixel questions <em>could</em> go in a standard ActionScript forum, but will likely get better answers in their <a href="http://www.box2d.org/forum/index.php">Box2D</a> and <a href="http://forums.flixel.org/">Flixel</a> forums.</p>

<h3><a href="http://www.kirupa.com/forum/">The Kirupa Forums</a></h3>

<p>The Kirupa Forums are my &ldquo;home&rdquo;; my forum of choice.</p>

<p>In the beginning, I bookmarked every ActionScript forum I could find, from <a href="http://actionscript.org/forums/">ActionScript.org</a> to an obscure section of the forums at <a href="http://armorgames.com/community/forum/39/programming-help/">ArmorGames</a>. Not sure which forum was &ldquo;the best&rdquo;, I would sometimes ask the same question in several places (in my defense, I didn&rsquo;t know any better).</p>

<p>I eventually started using the Kirupa forums more and more. I don&rsquo;t remember all the reasons why, but one major factor was that I often got better responses there, and would often get tied into long conversations. But in the end, the reason I finally settled down at the Kirupa forums is the same reason that I use ActionScript; it&rsquo;s not necessarily &ldquo;the best&rdquo;, I&rsquo;m just used to it. I&rsquo;m very comfortable there, and have had no reason to switch to a new forum.</p>

<p><span class='pullquote-right' data-pullquote='The Kirupa Forums are just the right size.'>The Kirupa Forums are just the right size. There are enough experienced ActionScripters (and even helpful beginners) to answer nearly every question within a day or two of its being posted. The questions that usually end up unanswered are the poorly written ones and &ldquo;not-really-questions&rdquo; like <em>&ldquo;i need to make a music player in flash cs5 that uses xml. help plz.&rdquo;</em></span></p>

<p>Sure, in a larger forum there are many more people answering questions, but after a few hours your question is already on page 2, which as we all know is where forum threads go to die. By then, no one except Google searchers will find your thread! Personally, I&rsquo;m not a fan of huge forums.</p>

<p>To boot, The Kirupa Forums have a nice set of <a href="http://www.kirupa.com/tutorials.htm">tutorials</a>, and also run <a href="http://www.kirupa.com/forum/forumdisplay.php?51-Contests">contests</a> with prizes from time to time. I thoroughly recommend <a href="http://www.kirupa.com/forum/">The Kirupa Forums</a> to any new ActionScripters.</p>

<h3>Other Forums</h3>

<p>As Kirupa.com is the only forum I&rsquo;m familiar with enough to give a full review, I don&rsquo;t know how other forums compare. Let me know what forums you have used, and how you feel about them in the comments below and I&rsquo;ll add your experiences in here.</p>

<h3><a href="http://stackoverflow.com/questions/tagged/actionscript-3">StackOverflow</a></h3>

<p>Although I haven&rsquo;t gotten deeply involved with this community, only using it on occasion, I feel it is a brilliant and magnificent way of asking and answering questions.</p>

<p><span class='pullquote-right' data-pullquote='It&#8217;s questions and answers, pure and simple.'>Unlike &ldquo;traditional forums&rdquo; where responses appear from top to bottom in chronological order, the best answers on StackOverflow &ldquo;float up&rdquo; to the top. There is no &ldquo;chit chat&rdquo; or &ldquo;small talk&rdquo;; even the comments that aren&rsquo;t actually &ldquo;answers&rdquo; are small and out of the way. It&rsquo;s questions and answers, pure and simple.</span></p>

<p>In the beginning, your powers are quite &ldquo;limited&rdquo;; you can&rsquo;t &ldquo;upvote&rdquo;, use links in your answers, or give those comments that aren&rsquo;t direct &ldquo;answers&rdquo;. To earn more privileges, you need to earn points by asking and answering questions well. Unlike Expert&rsquo;s Exchange (mentioned below), these points don&rsquo;t go away, but serve as a guard to keep spammers and &ldquo;low quality askers/answerers&rdquo; out. But as soon as you have racked up enough points to gain the trust of StackOverflow, you are free to ask, answer, and even edit across the site.</p>

<p>There are more things I love about StackOverflow&rsquo;s q/a system, but they are beyond the scope of this article and will have to be saved for another blog post.</p>

<h3><a href="http://www.experts-exchange.com/">Experts Exchange</a></h3>

<p>Be careful with this one. Experts Exchange is a <strong>paid service</strong>, and in my experience people tend to &ldquo;expect more&rdquo; out of a service they spent money on. I have more than once ran into people with the mindset &ldquo;I payed good money to ask a question here, and you have the audacity to accuse me of using the wrong publish settings? I don&rsquo;t need this kind of treatment!&rdquo;</p>

<p><em>Note that this is only my personal experience.</em> I have had positive responses as well, and others may also have had different results with EE.</p>

<p>Second, Experts Exchange <strong>really</strong> wants to earn money. It&rsquo;s not enough that people have to pay to ask questions there, but if you have ever stumbled across them on Google, you know that you can&rsquo;t even read answered questions without a paid membership.  (<a href="http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/ActionScript/Q_26120513.html">Exhibit A</a>)</p>

<p>You don&rsquo;t need a paid membership to get started at EE; you can still see and help answer <strong>unanswered</strong> questions with a &ldquo;free account&rdquo;. If you answer enough questions each month, you get a &ldquo;free one month membership&rdquo; which includes asking questions and viewing answered ones.</p>

<p>But if your amount of answered questions per month dips down below the minimum, you are back to a &ldquo;free account&rdquo; until you &ldquo;earn enough&rdquo; by answering questions. This is regardless of how many questions you answered in the past. The &ldquo;monthly minimum&rdquo; isn&rsquo;t high, but I still find what they are dong to be tacky and close to extortion.</p>

<p>The good news is, if you answer enough questions, you get a free t-shirt. :)</p>

<h3><a href="https://twitter.com/">Twitter</a></h3>

<p>Even though many have moved on to &ldquo;better technologies&rdquo;, there is still a slew of great Flash developers on Twitter, especially in the &ldquo;game development&rdquo; crowd. You can learn a lot from the things they tweet, and even start some pretty nice conversations.</p>

<p>Remember that many developers have busy lives outside of Twitter. If you do use Twitter to ask questions, as in all communities, sometimes it&rsquo;s better to ask a &ldquo;crowd&rdquo; of people (in this case, Tweeting to all your followers), rather than bothering a single person with your problems.</p>

<p>You would be surprised how often people ask for programming help on Twitter. If you are a fan of answering questions, keep an eye on the <a href="https://twitter.com/#!/search/%23as3">#as3</a> and <a href="https://twitter.com/#!/search/%23flashdev">#flashdev</a> tags if anyone needs help. Some Twitter applications, such as <a href="http://www.tweetdeck.com/">TweetDeck</a>, help you &ldquo;monitor&rdquo; tags and receive instant notifications when someone uses it in a Tweet.</p>

<p>The 140 character limit could be quite limiting, so sometimes it may benefit to invite the user to continue the conversation via an IM service such as <a href="http://www.skype.com/">Skype</a>. If you don&rsquo;t like giving out your Skype username online, create a new account used only for assisting people with ActionScript. This will also keep your programming contacts separate from your personal ones.</p>

<h3>IRC</h3>

<p>I&rsquo;m not an IRC person; I have used it, but I don&rsquo;t frequent anywhere. If anyone knows of any good IRC hangouts, please share them in the comments.</p>

<p><em>TODO: Insert conclusion that leaves readers inspired to go out and find a community to settle down into.</em></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[I Will Code for Free!]]></title>
    <link href="http://blog.iqandreas.com/i-will-code-for-free/"/>
    <updated>2012-04-16T06:54:00-05:00</updated>
    <id>http://blog.iqandreas.com/i-will-code-for-free</id>
    <content type="html"><![CDATA[<p>No, it&rsquo;s not a trap. There is no fine-print.</p>

<p>If you need any help with code but are working on a low budget, <strong>I&rsquo;m your man</strong>. I also do tutoring, helping to explain anything you may have missed or still don&rsquo;t understand fully when learning a new programming language.<!-- more --></p>

<h3>Why free?</h3>

<p>We have all been in that situation. You need a small feature added or have a minor item that needs fixing in a programming language you either have never used or are still new to. You have two options.</p>

<ol>
<li><p>Spend the next seven hours (or more) digging through Google trying to find something similar, and eventually hack and slash together something that <em>sort of</em> works the way you want it to.</p></li>
<li><p>Hire a professional at $75 per hour to do the job.</p></li>
</ol>


<p><span class='pullquote-right' data-pullquote='when someone familiar with the language could have done it in 15 minutes'>I have been faced with these choices, and it saddens me that I nearly always choose option #1, wasting <strong>hours</strong> of my time when someone familiar with the language could have done it in 15 minutes. But if I hired a professional to help me out for every 15 minute job that blocked my path&hellip;</span></p>

<h3>I can afford working free for 15 minutes</h3>

<p>Although I reserve the right to decline any job, <a href="http://blog.iqandreas.com/contact">contact me</a> if you need assistance with any of the following:</p>

<ul>
<li><p><strong>Fixing/Tweaking existing code</strong> &ndash; Do you want that menu on the left instead of the right and to expand when you click on it instead of hovering over it? I&rsquo;ll fix that.</p></li>
<li><p><strong>Debugging</strong> &ndash; I love searching for and fixing bugs, I don&rsquo;t know why.</p></li>
<li><p><strong>Explaining code</strong> &ndash; I <a href="http://iqandreas.github.com/actionscript/understanding-the-as3-event-system/part-1-the-basics/">tend</a> <a href="http://www.kirupa.com/forum/showthread.php?334440-Video-scrubber-positioning-problems">to</a> <a href="http://www.kirupa.com/forum/showthread.php?275077-1203-No-default-constructor">get</a> <a href="http://www.kirupa.com/forum/showthread.php?324256-1-class-to-multiple-library-assets-error-1203">illustrative</a> when explaining concepts in programming. Some find this uneccessary, but for others (including myself) it makes concepts easier to understand. Though usually my explanations aren&rsquo;t <em>that</em> long.</p></li>
<li><p><strong>Writing code</strong> &ndash; I will only write code for small and sometimes medium sized projects. If you want to create a MMORPG from scratch and need a free coder, search elsewhere. But if you want a script to verify the user&rsquo;s email address when they submit a comment, perfect!</p></li>
</ul>


<h3>Programming languages</h3>

<p>I am <em>very</em> comfortable with <strong>ActionScript</strong>, and have a firm grasp of the basics and syntax of <strong>PHP</strong>, <strong>JavaScript</strong>, and <strong>Java</strong>.</p>

<p><strong>I am not a designer.</strong> I can only help with code, not making things look nice (which includes HTML and CSS).</p>

<p>I can be contacted via the form below, or via the media listed on the <a href="http://blog.iqandreas.com/contact">contact</a> page.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why So Many Monologues?]]></title>
    <link href="http://blog.iqandreas.com/monologues/why-so-many-monologues/"/>
    <updated>2012-03-20T13:34:00-05:00</updated>
    <id>http://blog.iqandreas.com/monologues/why-so-many-monologues</id>
    <content type="html"><![CDATA[<p>I typically prefer the information in my posts to be more &ldquo;practical&rdquo;, but the last few posts have been mainly monologues. Bear with me though, I&rsquo;m working up to one central point, and after that I&rsquo;m back to writing useful information. <!-- more --></p>

<p>In the meantime, enjoy the following informative (and practical!) articles by Jackson Dunstan:</p>

<p><li class="flink com jacksondunstan_com"><a href="http://jacksondunstan.com/articles/1675">Top 10 Performance Tips for 2012</a></li>
<li class="flink com jacksondunstan_com"><a href="http://jacksondunstan.com/articles/1690">Top 10 Static vs. Non-Static</a></li>
<li class="flink com jacksondunstan_com"><a href="http://jacksondunstan.com/articles/1713">Top 10 Why Static is Slow</a></li></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Problems With Being Self Taught]]></title>
    <link href="http://blog.iqandreas.com/monologues/the-problems-with-being-self-taught/"/>
    <updated>2012-03-08T15:51:00-06:00</updated>
    <id>http://blog.iqandreas.com/monologues/the-problems-with-being-self-taught</id>
    <content type="html"><![CDATA[<p><em><strong>Note:</strong> I can only speak from personal experience on this issue, so I could use more input.</em></p>

<p>To say that I have been &ldquo;programming&rdquo; since I was 13 would be a stretch. I knew how to write code, but I was crippled by how much <em>Visual Studio.net</em> generated automatically for me. I never learned many of those automated tasks manually.</p>

<p>Aside from a programming class in high school with a <strong>fantastic</strong> teacher, I&rsquo;m entirely self taught. Being self taught is usually viewed as a great thing, though I cannot figure out why.<!-- more --></p>

<h3>Like a British person&rsquo;s teeth&hellip;</h3>

<p>For an embarrassingly long time I had large &ldquo;gaps&rdquo; in my knowledge. As one of many early personal examples, I never learned how to properly use for loops, so I tended to avoid them. In addition, I didn&rsquo;t realize you could access indexes in arrays with variables, and would instead copy and paste lines several times, filling in hard coded numbers.</p>

<p><span class='pullquote-right' data-pullquote='I&#8217;m not done learning'>Today, I still suffer from this. All but the most basic and common design patterns are still unfamiliar to me. In fact, properly organizing large projects is still a mountain of a task. I&rsquo;m not done learning.</span></p>

<p>Perhaps this problem would not exist if I had taken a single course from start to finish. I would take on new information one idea at a time and in an organized manner, rather than jump around from tutorial to tutorial picking up bits a pieces, missing chunks along the way.</p>

<h3>The dreaded intermediate phase</h3>

<p>There are beginner guides <em>galore</em> to any programming language or library you could imagine, from professional companies such as <a href="http://www.lynda.com/">Lynda</a> and <a href="http://active.tutsplus.com/sessions/as3-101/">Envato</a>, to independent bloggers such as <a href="http://www.untoldentertainment.com/blog/flash-and-actionscript-911">Untold Entertainment</a>, <a href="http://gamedev.michaeljameswilliams.com/as3-avoider-game-tutorial-base/">Michael James Williams</a> and <a href="http://www.emanueleferonato.com/">Emanuele Feronato</a>.</p>

<p><span class='pullquote-right' data-pullquote='&#34;I know the basics and the syntax. Now what?&#34;'>Alas, few beginner tutorials prepare you for the &ldquo;road ahead&rdquo;. In my experience, the most difficult stage in learning a new language is \&ldquo;I know the basics and the syntax. Now what?\&rdquo; During the &ldquo;intermediate&rdquo; phase, technical manuals and papers are too advanced, while beginner tutorials are too simple. Either there are too few resources for intermediate developers, or they are too diffiuclt to find.</span></p>

<p>It certainly isn&rsquo;t a help when beginner guides will take shortcuts (such as using timeline code rather than teaching to properly write classes) in an effort to make the new information easier to absorb. But similar to the &ldquo;automatically-generated-behind-the-scenes code&rdquo; in <em>Visual Studio.net</em>, this <strong>may</strong> have crippling effects on the students.</p>

<h3>Can you really call yourself self taught?</h3>

<p>On a related side note, successfully self-taught musicians sit down with their instrument of choice, and after much practice one day produce golden melodies from the tips of their fingers (or lips, depending on the instrument).</p>

<p>Can the same really be said for developers? I doubt anyone has summed up their history with &ldquo;One day I sat down at a compiler, not having read a single book on Objective C. It was hard at first, but after months of trial and error, my fingers eventually produced gold.&rdquo;</p>

<p>Yes, you may not have gone to an &ldquo;official&rdquo; school, but most books and online tutorials are set up in a manner similar to how you would learn a subject in a standard classroom.</p>

<p>Perhaps all the self-taught developer can say is &ldquo;The internet taught me.&rdquo;</p>

<h3>What about you?</h3>

<p>As mentioned, I can only speak from personal experience on being self educated. I have not taken any college level classes on software development, so I can&rsquo;t compare my expertise before and after the course. Would I still be facing the same problems after leaving college, or did I miss something crucial learning on my own?</p>

<p>I need more input. Are you a self taught developer? If so&hellip;</p>

<ul>
<li>What has your experience been learning to become a better self taught developer?</li>
<li>Are there more hinders self-taught individuals face? How can they be overcome?</li>
<li>How do you overcome the &ldquo;intermediate phase&rdquo; of learning a language?</li>
<li>Why is being self taught considered a positive thing? Is it?</li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[What Is a Theoretical Developer?]]></title>
    <link href="http://blog.iqandreas.com/monologues/what-is-a-theoretical-developer/"/>
    <updated>2012-03-02T14:56:00-06:00</updated>
    <id>http://blog.iqandreas.com/monologues/what-is-a-theoretical-developer</id>
    <content type="html"><![CDATA[<p><em><strong>Note:</strong> Take this post with a grain of salt. It&rsquo;s meant to be a slightly amusing rant, and should not be used as an official classification system for developers.</em> <img class="smiley" src="http://www.kirupa.com/forum/images/smilies/wink.gif" title=";)" ></p>

<p><strong>Engineers</strong>, <strong>Architects</strong>, and <strong>Chemists</strong> work with their hands on &ldquo;real life&rdquo; projects. They of course use their problem solving and thinking skills in their line of work, but in the end, they get paid to develop specific products with practical uses.</p>

<p><strong>Mathematicians</strong> and <strong>Theoretical Physicists</strong> do the exact opposite. They spend all day thinking, pondering, and mediating; finding better ways of describing the universe, and using their minds to solve problems that may not even exist in real life. <em>(Yes, I skewed those descriptions to fit the point I&rsquo;m making.)</em></p>

<p>Sometimes their work has practical applications, sometimes it does not.</p>

<h3>What is a theoretical developer?</h3>

<p>Similarly, <strong>Theoretical Developers</strong> are software developers who are more concerned with solving &ldquo;theoretical&rdquo; problems than getting any actual work done. When a problem arises, it is more beautiful to develop a solution where all the pieces fit together perfectly than to &ldquo;Just git &lsquo;er dun&rdquo;.</p>

<!-- more -->


<p><a href="http://xkcd.com/974/"><img class="center" src="http://imgs.xkcd.com/comics/the_general_problem.png"></a></p>

<p><strong>Software Engineers</strong> and <strong>Software Architects</strong> on the other hand use software development as a means to an end, a way to put food on the table or get a website up and running. They are more willing to take shortcuts even if doing so may break the Sacred Laws of OOP. <em>These people have also been caught placing code on the main timeline. (yuck!)</em></p>

<h3>How do you spot a Theoretical Developer?</h3>

<p>These elusive creatures often appear in the wild among Open Source Activists, Wikipedia Authors, and alas, some among Pyromaniacs, starting flame wars, aggressively trying to convince others that <em>their</em> technology is the best.</p>

<p>Some spend hours ranting on how the syntax for programming languages should theoretically be written, even though there is no chance of those changes being applied to the language (<a href="http://www.kirupa.com/forum/showthread.php?365748-How-definitions-should-%28theoretically%29-be-written-in-AS3"><em>ahem</em></a>).</p>

<p>Or sending code for game prototypes to potential employers that doesn&rsquo;t actually run because the only code written so far is for  a collision detecton API, rather than having focused on making the game playable.</p>

<h3>Are Theoretical Developers better than Software Engineers?</h3>

<p>I have previously jokingly compared Software Engineers to &ldquo;women of the night&rdquo;; just getting the job done for the pay check. I wish to revoke that statement, pleading beginner&rsquo;s insanity <em>(see <a href="http://www.smbc-comics.com/?id=2475">Mount Stupid</a>)</em>.</p>

<p>In fact, when comparing the progress of theoretical developers to that of &ldquo;real developers&rdquo;, usually it&rsquo;s the developers working on &ldquo;real&rdquo; projects that become successful. And as already mentioned, there are developers who love programming, while still earning money from the products they create (double bonus!).</p>

<p>So which one are you? A Software Engineer, a Theoretical Developer, or a mix of both?</p>

<p>Or perhaps the Theoretical Developer is just a fancy name I invented as an excuse for my lack of &ldquo;real life&rdquo; progress&hellip; <img class="smiley" src="http://www.kirupa.com/forum/images/smilies/trout.gif" title=";)" ></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Ubuntu: Adding FDT to the List of Applications]]></title>
    <link href="http://blog.iqandreas.com/actionscript/actionscript-in-ubuntu/ubuntu-adding-fdt-to-the-list-of-applications/"/>
    <updated>2012-01-17T08:48:00-06:00</updated>
    <id>http://blog.iqandreas.com/actionscript/actionscript-in-ubuntu/ubuntu-adding-fdt-to-the-list-of-applications</id>
    <content type="html"><![CDATA[<p>In this guide, we will add FDT to the list of installed applications, and optionally, install a script which &ldquo;resets&rdquo; the internal SWFViewer in case it won&rsquo;t open after closing improperly.</p>

<p><img class="center" src="http://blog.iqandreas.com/images/blog/fdt-in-ubuntu-applications-menu.png" title="FDT in Ubuntu Applications Menu" ></p>

<!-- more -->


<p><em>The following guide was written for 32bit FDT5, but may still work for future or previous versions of FDT. These instructions can of course also be used for any application that doesn&rsquo;t come with an Ubuntu installer, adjusting the  files appropriately.</em></p>

<p>If you are running Ubuntu, I&rsquo;m assuming you already know how to use the basics of the command line and how to manipulate (create, delete, change permissions) of files. If anyone wants more details, post a comment and I&rsquo;ll clarify.</p>

<p>I&rsquo;m assuming you have already <a href="http://fdt.powerflasher.com/buy-download/">downloaded FDT</a> (they have a free version if you aren&rsquo;t already using FDT) and extracted the archive.</p>

<p>I would recommend saving the files to <code>/opt/fdt5</code> (may require admin access, which is easily done without messing with the command line by running <code>gksu nautilus</code>, assuming you are still using the default file browser) Depending on what extraction tool you use, you may also need to change the permission settings for the files to allow folder access for all users.</p>

<h3>Download the FDT5 Launcher files</h3>

<p>If you want to do this the easy way, download the pre-made files from the <a href="https://github.com/IQAndreas/FDT-Ubuntu-Launcher-Files">GitHub repository</a> and install them to the locations specified in the README.</p>

<p><a href="https://github.com/IQAndreas/FDT-Ubuntu-Launcher-Files/zipball/master"><img class="favicon" src="http://blog.iqandreas.com/images/icons/icon_archive.gif"> https://github.com/IQAndreas/FDT-Ubuntu-Launcher-Files/zipball/master</a></p>

<p>You are all done. Enjoy!</p>

<p>Alternatively, you can do all the dirty work yourself (if so, keep reading).</p>

<h3>Creating the FDT5 Launcher Files manually</h3>

<p>Create a new file named FDT5.desktop with the following contents:</p>

<div><script src='https://gist.github.com/1626770.js?file=FDT5.desktop'></script>
<noscript><pre><code>[Desktop Entry]
Name=FDT5
#Comment=
Exec=fdt5
Icon=/opt/fdt5/fdt-icon.png
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;Application;IDE;</code></pre></noscript></div>


<p>If you want the file to be available to all users of the computer, save the file in
&ndash; <code>/usr/share/applications/</code>
Alternatively, if you only want the currently logged in user to have FDT show up in the application menu, save the file to
&ndash; <code>~/.local/share/applications/</code></p>

<p>Next, create the following script, and save it as <code>/usr/bin/fdt5</code></p>

<div><script src='https://gist.github.com/1626770.js?file=fdt5'></script>
<noscript><pre><code>#!/bin/sh
#export MOZILLA_FIVE_HOME=&quot;/usr/lib/xulrunner-1.9.2.17/&quot;
export MOZILLA_FIVE_HOME=&quot;/usr/lib/mozilla/&quot;

export LD_LIBRARY_PATH=${MOZILLA_FIVE_HOME}:${LD_LIBRARY_PATH}
export GDK_NATIVE_WINDOWS=1
export ECLIPSE_HOME=&quot;/opt/fdt5&quot;

$ECLIPSE_HOME/eclipse $*
</code></pre></noscript></div>


<p>Note that the script may be a tad more complicated than it needs to be, but this is the script I&rsquo;m using since I had to jump through a few hoops getting FDT to work properly in Ubuntu.</p>

<p>You also need to set the icon for the application. The default Eclipse icon is okay, but on my system, both Eclipse for Java and <a href="http://code.google.com/p/fb4linux/">FB4Linux</a> use that same icon, so I would prefer being able to tell them apart.</p>

<p>I included FDT&rsquo;s fancy, blue dodecahedron icon <a href="https://github.com/IQAndreas/FDT-Ubuntu-Launcher-Files/blob/master/fdt-icon.png">in the repository</a>, used with permission from Powerflasher GmbH. You can use the icon provided in the repository, or use your own, but which ever icon you use for FDT, make sure to save it to <code>/opt/fdt5/fdt-icon.png</code></p>

<p>Finally, if you want FDT to stay in the launcher bar, start up FDT, right-click the icon in the launcher, and make sure &ldquo;Keep in Launcher&rdquo; is checked.</p>

<p><img class="center" src="http://blog.iqandreas.com/images/blog/fdt-in-ubuntu-launcher-keep-in-launcher.png" title="FDT in the Ubuntu Launcher. Right click and make sure &#34;Keep in Launcher&#34; is checked." alt="FDT in the Ubuntu Launcher. Right click and make sure &#34;Keep in Launcher&#34; is checked."></p>

<h3>Cleaning the SWFViewer settings</h3>

<p>If the built in FDT SWFViewer quits improperly (which happens from time to time when running into AS3 errors) it will not open the next time you run the SWF. The solution is to delete a few config files for the plugin, which is a simple task, but gets annoying when you need to constantly delete the files.</p>

<p>The following script will delete said config files (assuming FDT is installed to <code>/opt/fdt5</code> as recommended) though I wish FDT had a button for this inside the IDE instead.</p>

<div><script src='https://gist.github.com/1626770.js?file=fdt5-clean'></script>
<noscript><pre><code># Clean out viewer settings for FDT
# Could remove the windows and MAC settings as well, but it seems a bit uneccessary. ;)

# 32 bit linux
rm -f /opt/fdt5/plugins/com.powerflasher.fdt.ui.swfViewer_5.0.0.1412/linux32/.SWFViewerCheck
rm -f /opt/fdt5/plugins/com.powerflasher.fdt.ui.swfViewer_5.0.0.1412/linux32/.SWFViewerLock
rm -f /opt/fdt5/plugins/com.powerflasher.fdt.ui.swfViewer_5.0.0.1412/linux32/.SWFViewerRestartInfo

# 64 bit linux
rm -f /opt/fdt5/plugins/com.powerflasher.fdt.ui.swfViewer_5.0.0.1412/linux64/.SWFViewerCheck
rm -f /opt/fdt5/plugins/com.powerflasher.fdt.ui.swfViewer_5.0.0.1412/linux64/.SWFViewerLock
rm -f /opt/fdt5/plugins/com.powerflasher.fdt.ui.swfViewer_5.0.0.1412/linux64/.SWFViewerRestartInfo</code></pre></noscript></div>


<p>Save the script to <code>/usr/bin/fdt5-clean</code> and run it by typing <code>fdt5-clean</code> into the command prompt. The script does not require admin rights to run as long as your FDT install folder has full permission for all users.</p>

<p>Leave any further questions or problems in the comments and I&rsquo;ll try to help sort them out.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[What Beginners Need to Know About Performance and Garbage Collection]]></title>
    <link href="http://blog.iqandreas.com/actionscript/actionscript-for-beginners/what-beginners-need-to-know-about-performance-and-garbage-collection/"/>
    <updated>2012-01-16T01:43:00-06:00</updated>
    <id>http://blog.iqandreas.com/actionscript/actionscript-for-beginners/what-beginners-need-to-know-about-performance-and-garbage-collection</id>
    <content type="html"><![CDATA[<p>Another category of beginner questions that often appear on the <a href="http://www.kirupa.com/forum/">Kirupa forums</a> are about performance and garbage collection. Some common concerns:</p>

<ul>
<li>How do I make sure my <code>MovieClips</code> are garbage collected? Is setting everything to <code>null</code> enough?</li>
<li>Should I always remove all my event listeners?</li>
<li>Someone told me it&rsquo;s better to use <code>int</code> instead of <code>uint</code> because it&rsquo;s more efficient.</li>
<li>I used <code>while(--i)</code> instead, because it is much more efficient than <code>for</code> loops.</li>
<li><code>hitTest()</code> is really slow! Every site tells me I should never use it.</li>
</ul>


<p>My answer to all those questions: <em>Don&rsquo;t worry about it</em>.</p>

<!-- more -->


<p>Don&rsquo;t get me wrong, if you are the type of person who worries about these sorts of things right now, you will make a terrific developer one day! But worrying about these things now is just going to make your code more complicated and much more difficult to manage.</p>

<h3>Strive to make your code clear and readable</h3>

<p>As a beginner, this should be your first and foremost rule. If you scratch your head every time you read your own code, coding will be overwhelming and debugging will be hell.</p>

<p>Take these two identical chunks of code as an example:</p>

<div><script src='https://gist.github.com/1625219.js?file=compass_rotation_compact.as'></script>
<noscript><pre><code>compass.rotation = Math.atan2(event.stageY - compass.y, event.stageX - compass.x) * (180/Math.PI) + 90;</code></pre></noscript></div>




<div><script src='https://gist.github.com/1625219.js?file=compass_rotation_expanded.as'></script>
<noscript><pre><code>//Get the location of the mouse relative to the compass
var dx:Number = event.stageX - compass.x;
var dy:Number = event.stageY - compass.y;

var radianRotation:Number = Math.atan2(dy, dx);
var degreeRotation:Number = radianRotation * (180/Math.PI);

//Offset the rotation by 90 degrees to make it show up properly
compass.rotation = degreeRotation + 90;</code></pre></noscript></div>


<p>The first chunk of code is much more efficient than the second, but I wouldn&rsquo;t want to be the developer that find bugs in that project.</p>

<h3>So should I never worry about performance?</h3>

<p>Not at this point, no. First make sure you have learned the basics and syntax of ActionScript.
Then, make sure you <strong>really</strong> know the basics of ActionScript (instead of just thinking that you do while perched <a href="http://www.smbc-comics.com/?id=2475">on top of mount stupid</a>. Believe me, we have all been there). <strong>Finally</strong> you can start learning about standard coding conventions and basic performance improvements.</p>

<p>Keep in mind, most performance optimization tips (such as using <code>int</code> instead of <code>uint</code>) will shave <em>milliseconds</em> off your total time if you do tens of thousands of calculations each frame.</p>

<p>Often times, the extra milliseconds won&rsquo;t make a hill of beans difference, so worrying about them while writing the code is a waste of resources. Test your code, and make sure your project works. Then, <strong>if</strong> (and only if!) there is a problem with performance after everything is complete and working, you can go back and find which areas need optimizing.</p>

<h3>Why Garbage Collection doesn&rsquo;t matter</h3>

<p>Same principle as with optimization, don&rsquo;t worry too much about garbage collection unless you are building an enterprise-level application. Flash is actually pretty good at taking care of things for you and making sure everything gets disposed of properly. Even if it misses an image here or there, what is one measly Bitmap for a computer with +2GB of RAM? Users won&rsquo;t notice the difference if your game uses 17 MB instead of 16 MB.</p>

<p>And remember, it&rsquo;s <strong>all</strong> disposed once you close the SWF anyway.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Humble AIR Bundle]]></title>
    <link href="http://blog.iqandreas.com/monologues/the-humble-air-bundle/"/>
    <updated>2011-12-26T05:58:00-06:00</updated>
    <id>http://blog.iqandreas.com/monologues/the-humble-air-bundle</id>
    <content type="html"><![CDATA[<p>I&rsquo;d like to say straight off the bat that this bundle does not exist. It&rsquo;s just an idea I have been playing with in my mind.</p>

<p>Adobe recently announced that they will no longer be releasing updates for AIR for Linux. This saddens me, mainly because the reason I switched from working with .Net to Flash was the &ldquo;multi-platformness&rdquo; &ndash; the ability to compile once and have your game or application run on any operating system (it has a proper name, but it&rsquo;s still on the tip of my tongue).<!-- more --></p>

<p>A few games in previous <a href="http://www.humblebundle.com/">Humble Indie Bundles</a> were actually Flash games (even if the players don&rsquo;t notice it); <a href="http://amanita-design.net/samorost-2/">Samorost 2</a>, <a href="http://machinarium.net/demo/">Machinarium</a>, and <a href="http://www.traumagame.com/">Trauma</a>. Even though Flash can&rsquo;t make the most powerful of games, it&rsquo;s fairly obvious that Flash games are at least playable.</p>

<p>AIR increases the functionality of Flash, and adds mobile devices to the available platforms, all with very little additional changes made to your existing game or application.</p>

<p>I&rsquo;m sure if a small group of Flash game developers teamed up &ldquo;Humble Bundle style&rdquo; they could release a bundle with multi-platform, DRM-free AIR games, with proceeds either going towards charities, or perhaps towards the open source developers working on the AIR binaries for Linux. In either case, the bundle would provide positive publicity for AIR.</p>

<p>I don&rsquo;t have the influence or resources to do this, but do <strong>you</strong>?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Is High Score Dead?]]></title>
    <link href="http://blog.iqandreas.com/monologues/is-high-score-dead/"/>
    <updated>2011-11-25T14:50:00-06:00</updated>
    <id>http://blog.iqandreas.com/monologues/is-high-score-dead</id>
    <content type="html"><![CDATA[<p>I have recently played with the thought of the classic high score system being &ldquo;dead&rdquo;. These viewpoints are from the perspective as a player rather than a developer.</p>

<!-- more -->


<p>Remember the good old days of playing Pac-Man at the arcade, burning quarter after quarter until you were #1? You could then laugh in the face of the last high score holder, and brag to all the local children and challenge them to beat your score.
<sub><sup><em>(Or maybe not, I was born a few years too late for the glory days of arcade games, so I&rsquo;m guessing at how the high scores worked back then)</em></sup></sub></p>

<p><img class="right" src="http://blog.iqandreas.com/images/blog/high-score-2011-11-25.small.png" title="Really really high high score" ></p>

<p>But today, with the rise of flash games, no matter how hard you work at getting to the top, your fantastic score of 189,335 points will place you at position #24,890 in the high score list, with the top scores always being held by cheaters or some Asian kid with an abnormal talent for games and hours of time on his hands.</p>

<p>Perhaps I&rsquo;m just a pessimist, but if there is no cosmic chance of me even showing up on the top 100, what&rsquo;s the point of replaying the game to get a better score?</p>

<p>So, what do you think? Did the widespread availability of the internet and the surprisingly large amount of people on this planet kill the classic high score system? (leave a comment if you disagree, I could be wrong)</p>

<p>Or is the high score system still kept alive by Facebook games where you only see the scores of your friends?</p>

<h3>High Score done right!</h3>

<p>I recently purchased the game <a href="http://spacechemthegame.com/">SpaceChem</a> by Zachtronics Industries.</p>

<blockquote><p><strong>SIDE NOTE:</strong> I have long been a fan of <a href="http://www.kongregate.com/accounts/krispykrem">that developer&rsquo;s flash games</a>, and I&rsquo;m happy his newest creation is having so much success. SpaceChem is one of my favorite games, and I would really recommend it if you enjoy puzzle games, and it definitely helps if you have a &ldquo;programmers mindset&rdquo;. You can <a href="http://store.zachtronicsindustries.com/product/spacechem">grab the demo</a> if you want to try it before purchasing the game.</p></blockquote>

<p>SpaceChem does an amazing job at including a high score system without &ldquo;intimidating&rdquo; the score you worked so hard for.</p>

<p>When you have finished a working design, you see a bar chart of how creation&rsquo;s efficiency compares to the average user. This allows you to see which areas you could realistically improve your score without being blown out of the water by Sum Yung Gui from Beijing.</p>

<p><img class="center" src="http://blog.iqandreas.com/images/blog/spacechem-high-score.small.png" title="Example SpaceChem high score result" ></p>

<p>If you know of any other games with unique and brilliant high score systems, share them in the comments.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Does "Ponycorns" Exploit the Mentally Ill?]]></title>
    <link href="http://blog.iqandreas.com/monologues/does-ponycorns-exploit-the-mentally-ill/"/>
    <updated>2011-06-04T14:15:00-05:00</updated>
    <id>http://blog.iqandreas.com/monologues/does-ponycorns-exploit-the-mentally-ill</id>
    <content type="html"><![CDATA[<p>Untold Entertainment recently released a new game, &ldquo;<a href="http://www.untoldentertainment.com/games/sissy/">Sissy&rsquo;s Magical Ponycorn Adventure</a>&rdquo;.</p>

<p><a href="http://www.untoldentertainment.com/games/sissy/"><img class="center" src="http://blog.iqandreas.com/images/blog/sissys-magical-ponycorn-adventure-title.jpg" title="Sissy's Magical Ponycorn Adventure" ></a></p>

<p>Already the game has had some positive media attention, from interviews on both local radio and television, to several internet news sites including <a href="http://ca.news.yahoo.com/blogs/good-news/toronto-five-old-cassie-creighton-video-game-takes-175342572.html">Yahoo news</a> and <a href="http://www.boingboing.net/2011/06/03/sissys-magic-ponycor.html">BoingBoing</a>.</p>

<!-- more -->


<p>After only having been released for soon two weeks (as of today, June 4, 2011) the game has received about 200,000 plays and $2,500 in donations (and more is likely to follow as time progresses).</p>

<h3>This game must be awesome!!</h3>

<p>Is the game deserving of all this media attention by being awesome and fantastic, with hours of intricate puzzles, stunning graphics, and gripping story lines? No.</p>

<p>Then why so much popularity? The graphics, sound effects (including most of the dialog), and story were all designed by a 5 year old, little girl.</p>

<p>Assume for a second that this game had been released on <a href="http://www.newgrounds.com/">Newgrounds</a> (which is, from what I hear, the #1 portal for Flash content with not enough quality to be allowed on portals with &ldquo;higher standards&rdquo;) and <a href="http://twitter.com/UntoldEnt">Ryan Creighton</a> (the father and lead developer) had proudly announced that he had produced the game all on his own.</p>

<p>Ryan could then sit back and expect a steady stream of classic Newgrounds comments such as &ldquo;<em>OMGWTF gay</em>&rdquo;, &ldquo;<em>-9999/10</em>&rdquo;, and &ldquo;<em>giv me my 2mins of life bak</em>&rdquo;.</p>

<h3>&ldquo;Ponycorns&rdquo; exploits the mentally ill</h3>

<p>At this point you are probably calling me an insensitive prick and have likely already started to flame me in the comments. But, I am trying to make a point here.</p>

<p>This game takes advantage of at least two &ldquo;weaknesses&rdquo; (couldn&rsquo;t find a better word) of human nature.</p>

<h3>FW: FW: FW: FW: FW: Funny pictures (must see!)</h3>

<p>First, people love babies, young children, and kittens (for various reasons; you can likely dig up a lot of research on yourself). Anyone who doesn&rsquo;t believe me apparently doesn&rsquo;t have family members who have learned to use the &ldquo;forward&rdquo; button on their emails.</p>

<p><a href="http://twitter.com/seb_ly">Seb Lee-Delisle</a>&rsquo;s iPhone app, <a href="http://kittenconveyorbelt.com/">Kitten Conveyorbelt</a>, is another game which takes advantage of this exploit ($1 for a slideshow of cats, seriously?)</p>

<p>Somewhat related, the &ldquo;<a href="http://www.buzzfeed.com/awesomer/selling-8-beyblades-to-replace-destroyed-bathtub">8 Beyblades for sale on eBay</a>&rdquo;, despite having several &ldquo;fake bids&rdquo;, still received a lot more bid amounts than selling the Beyblades on their own would have. Why? People feel sorry for these crying little children and their situation.</p>

<p>(Next time you try selling your car, include a picture of yourself next to it crying and see if it also works with grown-ups)</p>

<h3>Good job, sweetie. I&rsquo;ll put this up on the fridge where everyone can see it</h3>

<p>Second, humans (at least the empathetical ones) will value items and achievements higher if they were produced when the &ldquo;creator&rdquo; was under certain limitations (in the case of Cassie Creighton, limitations in age and game development experience).</p>

<ul>
<li>Did your mother put your paintings of a giraffe with rockets strapped to it on the refrigerator because your work was comparable to Rembrandt?</li>
<li>And why would anyone otherwise care about &ldquo;special olympics&rdquo;?</li>
<li>And what makes Michael Phelps much more famous than all other swimmers?</li>
</ul>


<p>On a related note, even I can draw better than this elephant! Why don&rsquo;t my YouTube videos get 6.5 million views?</p>

<div style="text-align: center;"><iframe allowfullscreen="" frameborder="0" height="349" src="http://www.youtube.com/embed/He7Ge7Sogrk" width="425"></iframe></div>


<h3>What can we learn from all this?</h3>

<p>Other than the obvious point of &ldquo;Taking advantage of human psychological flaws leads to more attention and in return buckets of easy money&rdquo;, there is a broader point to be made (which is by far no new idea):</p>

<blockquote><p>Presentation is key</p></blockquote>


<p>As I still haven&rsquo;t produced even a single game, I feel like some sort of hypocrite (did I use that word correctly or is there a better term?) telling people how to design their games. After all, what do I know?</p>

<p>Luckily, the principle has many more applications. Often when presenting something, you are very limited, such as the title of a blog post, description of a game, or a small introduction in a conversation or speech.</p>

<p>Presenting any creation as &ldquo;just another of many&rdquo; will quickly cause the listener to loose interest. What makes your product unique? How does it stand out from the rest? (Note that I do not support lying or over-exaggerating in order to glorify what you are selling! Scumbags&hellip;)</p>

<p>Perhaps it will gain more attention if you release it for a good cause, such as <a href="http://www.triqui.com/2010/05/03/rebuild-chile/">donating all income from a game to earthquake/tsunami victims</a>.</p>

<p>Perhaps even take advantage of a few other human psychological flaws, such as curiosity to reel in your listeners (this blog post title got you here, didn&rsquo;t it?)</p>

<h3>Does Apple exploit the mentally ill?</h3>

<p>I simply cannot end a discussion on exploiting human psychology without bringing up Apple.</p>

<p><span class='pullquote-right' data-pullquote='Apple sells a religion, not a product'>As I have said many times before (which someone said before me, but I don&rsquo;t remember the source), <em>Apple sells a religion, not a product</em>. When you buy their iPhone, you buy an experience, and a ticket into the community of awesome people.</span></p>

<p>In a nutshell &ldquo;<strike>Cigarettes</strike> Apple&rsquo;s products make you look cool!&rdquo;</p>

<hr />

<h2>FAQ</h2>

<h3>Is Ryan Creighton exploiting our weaknesses for monetary gain?</h3>

<p>It&rsquo;s possible, but I doubt it. <img class="smiley" src="http://www.kirupa.com/forum/images/smilies/wink.gif" title=";)" ></p>

<p>This may be a good place to add that all donations and income from Mochi Ads are going directly to Cassie&rsquo;s college fund (so help her education, and donate! Link is on the <a href="http://www.untoldentertainment.com/games/sissy/">game&rsquo;s page</a>).</p>

<h3>Does this mean you hate the game?? And little children?!?</h3>

<p>Alas, I am neither a Vulcan nor a sociopath, and susceptible to the same flaws of human psychology as everyone else, so yes, I thought it was cute.</p>

<p>The one thing in specific I enjoyed were the small witty bits of dialog. They reminded a bit of the the comments found in <a href="http://en.wikipedia.org/wiki/Lemony_Snicket">Lemony Snicket</a>&rsquo;s books (<a href="http://soundcloud.com/iqandreas/lemony-snicket-defines-denouement">sample excerpt</a>).</p>

<p>My favorite quotes from the game (spoiler alert)</p>

<blockquote><p>Your&#8217;e a mouse now. How do you like THEM apples?<br/>That&#8217;s what you get for being evil! AND a lemon!</p></blockquote>


<h3>Did you write this post to stir up conflict and flame wars, or perhaps to ride the wake of Ponycorn&rsquo;s success?</h3>

<p>Neither, by writing this post I&rsquo;m avoiding the PHP work on my plate, and since I&rsquo;m still getting <em>something</em> done, I can avoid the feelings of guilt that come from procrastinating my <em>real</em> work.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Experiment: Drop Painter]]></title>
    <link href="http://blog.iqandreas.com/actionscript/experiments/experiment-drop-painter/"/>
    <updated>2011-06-03T17:12:00-05:00</updated>
    <id>http://blog.iqandreas.com/actionscript/experiments/experiment-drop-painter</id>
    <content type="html"><![CDATA[<p>No, it&rsquo;s not painting with drops (though, that seems like a great idea for another project). Instead this experiment drops pieces of a painting down from above which eventually form to assemble a complete picture.</p>

<p><a href="http://iqandreas.isbetterthanyou.org/public/kirupa.com/square-contest-2011/"><img class="center" src="http://iqandreas.isbetterthanyou.org/public/kirupa.com/square-contest-2011/experiment-drop-painter-preview-image.png"></a>
<em>Click the image to go open the SWF</em></p>

<!-- more -->


<p>The code is written in AS3 and uses <a href="http://www.box2dflash.org/">Box2D</a> for the physics and <a href="http://www.minimalcomps.com/">MinimalComps</a> for the components.</p>

<p>At first I wrote the code up as a prototype just to test a concept (and rather than rewrite the code cleanly, I just kept adding onto it so it became one tightly-coupled mess).</p>

<p>I later entered it into a <a href="http://www.kirupa.com/forum/showthread.php?362779-Information-and-Rules!">contest</a> held on the <a href="http://www.kirupa.com/forum/">Kirupa Forums</a>, and modified it slightly to fit the contest theme.</p>

<p><a href="https://github.com/IQAndreas/Drop-Painter-Experiment">The source is available on GitHub</a> in case anyone is curious how it was achieved (and yes, I did cheat. It&rsquo;s not actually dynamic. The movement of all those shapes are &ldquo;pre-baked&rdquo; during the &ldquo;Loading&rdquo; screen and simply played back afterwards, which is why it is able to take up so little CPU on playback. <img class="smiley" src="http://www.kirupa.com/forum/images/smilies/trout.gif"></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Developing for the Playbook: Chapter 3 - the Emulator]]></title>
    <link href="http://blog.iqandreas.com/monologues/developing-for-the-playbook-chapter-3-the-emulator/"/>
    <updated>2011-03-30T04:50:00-05:00</updated>
    <id>http://blog.iqandreas.com/monologues/developing-for-the-playbook-chapter-3-the-emulator</id>
    <content type="html"><![CDATA[<p><strong>DISCLAIMER:</strong> This is the most rediculous thing I have ever done. Please ignore it. ;)</p>

<p><a href="http://us.blackberry.com/developers/tablet/playbook_offer.jsp"><img class="center" src="http://2.bp.blogspot.com/-5xwNp6B-g3k/TZL9dOkh0DI/AAAAAAAAACU/HIBnOj0qhp8/s400/playbook1.png" width="400" height="250"></a></p>

<!-- more -->


<p><em>TODO:</em> Insert chapter 1. (I was too lazy to repeat the steps just to take screenshots of the process. I don&rsquo;t feel like going through that again.)</p>

<p><em>TODO:</em> Insert chapter 2. (Same reason as for chapter 1)</p>

<h3>Chapter 3: The Emulator</h3>

<p><img class="center" src="http://1.bp.blogspot.com/-_iF-4bFq3f0/TZL9zEJwyhI/AAAAAAAAACc/Ns8Xv8s_3pw/s400/playbook2.png" width="400" height="250"></p>

<p><img class="center" src="http://2.bp.blogspot.com/-1mZ5GX2WL9M/TZL9zTik2QI/AAAAAAAAACk/5T9tOdGI00s/s400/playbook3.png" width="400" height="250"></p>

<p><img class="center" src="http://4.bp.blogspot.com/-ytdmr64dOWQ/TZL9zbvuZtI/AAAAAAAAACs/zLctegP_xvc/s400/playbook4.png" width="400" height="250"></p>

<p><img class="center" src="http://1.bp.blogspot.com/-WdPZlDdaTao/TZL9zR3fY9I/AAAAAAAAAC0/wSRsrJ1X9bg/s400/playbook5.png" width="400" height="250"></p>

<p><img class="center" src="http://1.bp.blogspot.com/-WdPZlDdaTao/TZL9zR3fY9I/AAAAAAAAAC0/wSRsrJ1X9bg/s400/playbook5.png" width="400" height="250"></p>

<p><img class="center" src="http://1.bp.blogspot.com/-WdPZlDdaTao/TZL9zR3fY9I/AAAAAAAAAC0/wSRsrJ1X9bg/s400/playbook5.png" width="400" height="250"></p>

<p><img class="center" src="http://1.bp.blogspot.com/-WdPZlDdaTao/TZL9zR3fY9I/AAAAAAAAAC0/wSRsrJ1X9bg/s400/playbook5.png" width="400" height="250"></p>

<p><img class="center" src="http://1.bp.blogspot.com/-WdPZlDdaTao/TZL9zR3fY9I/AAAAAAAAAC0/wSRsrJ1X9bg/s400/playbook5.png" width="400" height="250"></p>

<p><img class="center" src="http://1.bp.blogspot.com/-WdPZlDdaTao/TZL9zR3fY9I/AAAAAAAAAC0/wSRsrJ1X9bg/s400/playbook5.png" width="400" height="250"></p>

<p><img class="center" src="http://1.bp.blogspot.com/-WdPZlDdaTao/TZL9zR3fY9I/AAAAAAAAAC0/wSRsrJ1X9bg/s400/playbook5.png" width="400" height="250"></p>

<p><img class="center" src="http://1.bp.blogspot.com/-WdPZlDdaTao/TZL9zR3fY9I/AAAAAAAAAC0/wSRsrJ1X9bg/s400/playbook5.png" width="400" height="250"></p>

<p><img class="center" src="http://2.bp.blogspot.com/-9vMLH7_ysEs/TZL9zynCC9I/AAAAAAAAAC8/vQjLgKEAYR8/s400/playbook6.png" width="400" height="250"></p>

<p>Stay tuned for <strong>&ldquo;Chapter 4: The Code Signing!&rdquo;</strong></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Understanding the AS3 Event System #3 - Easy Event Bubbling]]></title>
    <link href="http://blog.iqandreas.com/actionscript/understanding-the-as3-event-system/part-3-easy-event-bubbling/"/>
    <updated>2010-10-19T07:23:00-05:00</updated>
    <id>http://blog.iqandreas.com/actionscript/understanding-the-as3-event-system/part-3-easy-event-bubbling</id>
    <content type="html"><![CDATA[<p>This thread is part 3 in the &ldquo;<a href="http://blog.iqandreas.com/actionscript/understanding-the-as3-event-system/">Understanding the AS3 Event System</a>&rdquo; series. It continues on the &ldquo;office&rdquo; illustration used in <a href="http://blog.iqandreas.com/actionscript/understanding-the-as3-event-system/part-1-the-basics">part 1</a> and <a href="http://blog.iqandreas.com/actionscript/understanding-the-as3-event-system/part-2-custom-events">part 2</a>. If you have not read the previous parts, it is recommended that you do so.</p>

<p>This part describes how <em>&ldquo;Event Bubbling&rdquo;</em> works. Note that this is a strong simplification of the actual system (which is a bit more complex, but in the next part I will elaborate on that system), but for 99% of all Event uses, this is the only thing you really need to know about Event Bubbling.</p>

<!-- more -->


<hr />

<p>At the office I work, a large part of our work system is set up as a hierarchy of responsibility and work delegation.</p>

<h4>The Corporate Ladder</h4>

<p>At the very top of the tree is Mr. Stan Stage. He&rsquo;s a great guy. Very friendly, a nice father figure, and a really good boss. He is the boss of all bosses, and in the end, everyone reports to him.</p>

<p>Since there is so much information passed around the office each day, he delegates most of the tasks to a handful of people who work right under him. These people are all <em>&ldquo;second in command&rdquo;</em>. One of these second in command is my boss. Unlike Mr. Stage, my boss is very annoying and difficult, and to avoid his wrath, I will exclude his name, and instead just call him <em>&ldquo;My Boss&rdquo;</em>.</p>

<p>My Boss has about 20 people working under him, including me. It&rsquo;s not a great position to be in, but it&rsquo;s still a very rewarding job. Some of us <em>&ldquo;third in command&rdquo;</em> workers have people working directly under us.</p>

<p>I am one of the lucky ones, and have five interns working directly for me. Since I am their boss, they obey my every whim, such as getting coffee for me each morning, or taking out my dry-cleaning. Even though they are only interns, they are still considered to be <em>&ldquo;fourth in command&rdquo;</em>.</p>

<p>Since a great deal of what we do at the Office is reported via <code>Events</code>, my interns are expected to use the event system to report any changes just like the rest of us.</p>

<p>For efficiency&rsquo;s sake, my five interns have their desks very close to my cubicle, so whenever they <code>dispatch</code> an <code>event</code> (by standing up and shouting for example <em>&ldquo;I was <u>hovered</u>!&rdquo;</em>) I hear it immediately.</p>

<p>Now, there are two types of <em>Events</em>; Events that Bubble, and Events that do not Bubble.</p>

<h4>Non-Bubbling Events</h4>

<p>Some Events are only important to the person to which it actually happened. For instance, one day one of my interns, Chris, stands up and yells <em>&ldquo;Hey everyone, I got a <u>new car</u>!&rdquo;</em></p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="n">dispatchEvent</span><span class="o">(</span><span class="k">new</span> <span class="kt">Event</span><span class="o">(</span><span class="s2">&quot;new_car&quot;</span><span class="o">));</span>
</span></code></pre></td></tr></table></div></figure>


<p>A few of my other interns reacted. However, I honestly did not care. My Boss sure as hell doesn&rsquo;t care. And as nice of guy Steve Stage is, he really doesn&rsquo;t care either.</p>

<p>I&rsquo;m not saying that Chris&rsquo;s <code>Event</code> wasn&rsquo;t important, in fact, it was quite important since it allows him to do his job better and will definitely affect his work. However, there is no need to tell as many people about it as possible. The only people who need to know about the event are people who specifically asked Chris to let them know whenever he got a new car.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="n">chris</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="s2">&quot;new_car&quot;</span><span class="o">,</span> <span class="n">talkToChrisAboutTheCar</span><span class="o">);</span>
</span></code></pre></td></tr></table></div></figure>


<p>Those Events <u>do not Bubble</u> up the corporate ladder.</p>

<h4>Events that Bubble</h4>

<p>Now, clicks are VERY important in my line of work (in fact, that&rsquo;s how we get paid).</p>

<p>We want to let as many people as possible who want to know about the clicks to know about the clicks, but if every single person just stood up and yelled <em>&ldquo;Someone was clicked!&rdquo;</em> whenever they found out about it, it would be one disorganized mess and you would hear about the same gossip from eight different people. Instead, we have an organized system for letting everyone in charge know about it.</p>

<h4>Bubbling Events up the Ladder</h4>

<p>One day Chris stands up and yells out to everyone <em>&ldquo;I was <u>clicked</u>!&rdquo;</em> (<code>dispatching</code> the <code>event</code> to everyone that may be <code>listening</code> to him. Not many people are usually listening to Chris (in fact, most people at the office don&rsquo;t even know any of my interns). So, Chris only tells everyone specifically listening to him about the <code>"click"</code> event.</p>

<p>Then Chris walks over to me and says <em>&ldquo;Andreas. I was <u>clicked</u>. All the information on the click is available in this Event folder.&rdquo;</em></p>

<p>Now it&rsquo;s my turn. I stand up and yell <em>&ldquo;I was <u>clicked</u>!&rdquo;</em> (I could tell them <em>&ldquo;someone in my department was clicked&rdquo;</em>, but since my interns work for me so closely, their work is considered to be part of my work) A few people are listening to me for the <code>"clicked"</code> event, (including Nico and Bob) and walk up to me asking for more information. I give them both the file so they have all the information on the event that they need.</p>

<p>Then, I barge into the office of my Boss, telling him all about the event, and handing him a copy of the information. He in turn switches on his fancy intercom system (since he is second in command, he gets certain perks, and is paid too much to have to yell across the hallway) and announces to everyone in the office <em>&ldquo;Attention anyone who is listening to me. I was just <u>clicked</u>.&rdquo;</em> A few people are <code>listening</code> to him, and respond.</p>

<p>Finally, my Boss knocks on the door of Steve Stage and tells him all about the click event. Now, at last, Mr. Stage announces the <code>"click"</code> event for the <strong>last</strong> time, telling everyone who is <code>listening</code> to him about the &ldquo;click&rdquo;.</p>

<p>After that it is done. Everyone who needs to know about the <code>Event</code> knows about it.</p>

<h4>Now why is Bubbling so important?</h4>

<p>Let&rsquo;s take the example of Betty, who works in accounting. In order to do her job property, she needs to know about every single time a client <code>"clicked"</code> an employee.</p>

<p>She could listen to every single employee for the <code>"click"</code> event, but this is a VERY inefficient system. And every time there is a new employee she would need to start listening to them, and when an employee leaves, she needs to remember to stop listening to them.</p>

<p>Instead, because of our nifty little bubbling system, Betty ONLY needs to listen to Mr. Stage for the <code>"click"</code> event. Since those events <code>bubble</code> up to Steve Stage, she will be notified of <strong>every single click event</strong> directly from Steve Stage.</p>

<h4>EXTRA NOTE: Events only bubble upwards</h4>

<p>Let&rsquo;s say one day I&rsquo;m working at my desk, when a client <code>"clicks"</code> me directly instead of clicking one of my interns. I stand up and yell to everyone who is listening to me that <em>&ldquo;I was <u>clicked</u>&rdquo;</em>, but I do not need to directly tell any of my interns about the click. Unless my interns are specifically listening to me, they will not know about the click and will keep carrying on their work undisturbed. The interns will NOT dispatch any <code>"click"</code> event either.</p>

<p>The only one who needs to know is My Boss. The events only bubble &ldquo;up&rdquo; the corporate ladder, not down.</p>

<h4>So who was clicked first?</h4>

<p>In order to file the proper paperwork (and hand out promotions or raises where needed) Betty needs to know exactly which person it was who was <code>"clicked"</code> first. Luckily, all this information is perfectly filled out in the <code>Event</code> object (the folder containing all the information).</p>

<p>There are two names in the <code>Event</code> object, <code>target</code> and <code>currentTarget</code>. Flash assigns these two names automatically when the <code>Event</code> is dispatched.</p>

<p>These two properties tend to cause a lot of confusion among beginners. Sometimes they refer to the same person, sometimes they do not. To explain the difference, let&rsquo;s take another example.</p>

<p>Nico is listening to me for the <code>"clicked"</code> event.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="n">andreas</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="s2">&quot;clicked&quot;</span><span class="o">,</span> <span class="n">onClick</span><span class="o">);</span>
</span></code></pre></td></tr></table></div></figure>


<p>Chris, my intern, is clicked, and stands up and tells everyone about it. Nico doesn&rsquo;t even know Chris and therefore doesn&rsquo;t even know about the event. Chris tells me about the event and hands me all the information.</p>

<p>Now, I stand up and tell everyone <em>&ldquo;I was clicked&rdquo;</em>. Nico is listening to me (Andreas) for the event, and walks over to gather all the information.</p>

<p>Then the event continues to bubble upwards to My Boss and finally Stan Stage.</p>

<p><strong>target</strong> refers to the person who first dispatched the event. In this case, Chris would be the target.
<strong>currentTarget</strong> refers to the person you were listening to who told you about the event.</p>

<p>Think about <code>currentTarget</code> for a second. For Nico, <code>currentTarget</code> would refer to me, <u>Andreas</u>. However, since Betty is listening to Stan Stage for the Event, the <code>currentTarget</code> property in her event file would refer to <u>Mr. Stage</u>.</p>

<h4>Using currentTarget to your advantage</h4>

<p>Why does the <code>currentTarget</code> property even exist? I mean if you added the event listener to an object, of course you know what that object is, and therefore the property is pretty much worthless.</p>

<p>However, if used properly, it can save you a lot of code! For instance, perhaps you have several buttons on the stage <code>homeButton</code>, <code>aboutButton</code>, <code>contactButton</code>, <code>newsButton</code>, etc. You want the button to scale up when it is clicked. You could add the event listeners like this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="n">homeButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="n">MouseEvent</span><span class="o">.</span><span class="na">CLICK</span><span class="o">,</span> <span class="n">homeButtonClicked</span><span class="o">);</span>
</span><span class='line'><span class="n">aboutButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="n">MouseEvent</span><span class="o">.</span><span class="na">CLICK</span><span class="o">,</span> <span class="n">aboutButtonClicked</span><span class="o">);</span>
</span><span class='line'><span class="n">contactButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="n">MouseEvent</span><span class="o">.</span><span class="na">CLICK</span><span class="o">,</span> <span class="n">contactButtonClicked</span><span class="o">);</span>
</span><span class='line'><span class="n">newsButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="n">MouseEvent</span><span class="o">.</span><span class="na">CLICK</span><span class="o">,</span> <span class="n">newsButtonClicked</span><span class="o">);</span>
</span><span class='line'>
</span><span class='line'><span class="kd">function </span><span class="nf">homeButtonClicked</span><span class="o">(</span><span class="n">mouseEvent</span><span class="o">:</span><span class="kt">MouseEvent</span><span class="o">):</span><span class="kt">void</span>
</span><span class='line'><span class="o">{</span>
</span><span class='line'>   <span class="n">homeButton</span><span class="o">.</span><span class="na">scaleX</span> <span class="o">=</span> <span class="mf">1.2</span><span class="o">;</span>
</span><span class='line'>   <span class="n">homeButton</span><span class="o">.</span><span class="na">scaleY</span> <span class="o">=</span> <span class="mf">1.2</span><span class="o">;</span>
</span><span class='line'><span class="o">}</span>
</span><span class='line'>
</span><span class='line'><span class="kd">function </span><span class="nf">aboutButtonClicked</span><span class="o">(</span><span class="n">mouseEvent</span><span class="o">:</span><span class="kt">MouseEvent</span><span class="o">):</span><span class="kt">void</span>
</span><span class='line'><span class="o">{</span>
</span><span class='line'>   <span class="n">aboutButton</span><span class="o">.</span><span class="na">scaleX</span> <span class="o">=</span> <span class="mf">1.2</span><span class="o">;</span>
</span><span class='line'>   <span class="n">aboutButton</span><span class="o">.</span><span class="na">scaleY</span> <span class="o">=</span> <span class="mf">1.2</span><span class="o">;</span>
</span><span class='line'><span class="o">}</span>
</span><span class='line'><span class="c1">//etc...</span>
</span></code></pre></td></tr></table></div></figure>


<p>That means, creating a different handler function for each button, which works, but creates <strong>a lot</strong> of extra code. Then if you want to change details of what happens when a button is clicked, you would need to update every single function.</p>

<p>Instead, you can create <em>one single function</em> which handles the clicks of <em>all</em> buttons. You can calculate which button needs to be pressed by using the <code>currentTarget</code> property.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="n">homeButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="n">MouseEvent</span><span class="o">.</span><span class="na">CLICK</span><span class="o">,</span> <span class="n">navigationButtonClicked</span><span class="o">);</span>
</span><span class='line'><span class="n">aboutButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="n">MouseEvent</span><span class="o">.</span><span class="na">CLICK</span><span class="o">,</span> <span class="n">navigationButtonClicked</span><span class="o">);</span>
</span><span class='line'><span class="n">contactButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="n">MouseEvent</span><span class="o">.</span><span class="na">CLICK</span><span class="o">,</span> <span class="n">navigationButtonClicked</span><span class="o">);</span>
</span><span class='line'><span class="n">newsButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="n">MouseEvent</span><span class="o">.</span><span class="na">CLICK</span><span class="o">,</span> <span class="n">navigationButtonClicked</span><span class="o">);</span>
</span><span class='line'>
</span><span class='line'><span class="kd">function </span><span class="nf">navigationButtonClicked</span><span class="o">(</span><span class="n">mouseEvent</span><span class="o">:</span><span class="kt">MouseEvent</span><span class="o">):</span><span class="kt">void</span>
</span><span class='line'><span class="o">{</span>
</span><span class='line'>   <span class="kd">var</span> <span class="n">pressedButton</span><span class="p">:</span><span class="kt">DisplayObject</span> <span class="o">=</span> <span class="n">mouseEvent</span><span class="o">.</span><span class="na">currentTarget</span> <span class="k">as</span> <span class="n">DisplayObject</span><span class="o">;</span>
</span><span class='line'>   <span class="n">pressedButton</span><span class="o">.</span><span class="na">scaleX</span> <span class="o">=</span> <span class="mf">1.2</span><span class="o">;</span>
</span><span class='line'>   <span class="n">pressedButton</span><span class="o">.</span><span class="na">scaleY</span> <span class="o">=</span> <span class="mf">1.2</span><span class="o">;</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>That&rsquo;s a lot less code! Now, if you need to change the scaling to 1.3, you only have to update it in one single place!</p>

<p>If you want to attach additional properties to the buttons, (such as setting some custom scale value for each button) you can use the Dictionary object. Look in the FAQ under the appropriate category for links to explanations and example code:
<a href="http://iqandreas.blogspot.com/2009/09/most-common-flash-questions-as3-faq.html">http://iqandreas.blogspot.com/2009/09/most-common-flash-questions-as3-faq.html</a></p>

<p>This is how Flash bubbles its events.</p>

<p>Next step, how to make your own events bubble (The fourth part of this series is still on my TODO list ;)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Understanding the AS3 Event System #2 - Custom Events]]></title>
    <link href="http://blog.iqandreas.com/actionscript/understanding-the-as3-event-system/part-2-custom-events/"/>
    <updated>2010-10-12T07:53:00-05:00</updated>
    <id>http://blog.iqandreas.com/actionscript/understanding-the-as3-event-system/part-2-custom-events</id>
    <content type="html"><![CDATA[<p>This thread is part 2 in the &ldquo;<a href="http://blog.iqandreas.com/actionscript/understanding-the-as3-event-system/">Understanding the AS3 Event System</a>&rdquo; series. It continues on the &ldquo;office&rdquo; illustration used in <a href="http://blog.iqandreas.com/actionscript/understanding-the-as3-event-system/part-1-the-basics">part 1</a>. If you have not read part 1, it is recommended that you do so.</p>

<p>I originally wrote this thread as a response to a Kirupa forum thread: <a href="http://www.kirupa.com/forum/showthread.php?t=355040"><img class="favicon" src="http://www.kirupa.com/favicon.ico"> Passing a string to be a custom event</a></p>

<p>This is my first draft, so any opinions or thoughts are deeply appreciated, especially if there is anything you still don&rsquo;t fully understand or would like me to clarify further.</p>

<!-- more -->


<hr />

<p>Listen, don&rsquo;t tell my boss, but those days when work gets slow, I fire up some StarCraft! StarCraft is no fun alone, so Nico, Bob, Larry, and I all play against eachother. The problem is that we all need to be logged on at the same time in order to play together. I&rsquo;m the one who plays the most, so I am the &ldquo;Game Master&rdquo;; the one who starts up the server, chooses a map, and waits for everyone else to join in.</p>

<p>We need some way to alert each other when I start up a StarCraft game, <em>and</em> keep it a secret from my boss (he reads all our emails, so I can&rsquo;t tell them via email). So, we use the Event system!</p>

<h4>Custom Event Strings</h4>

<p>We have planned that whenever I am about to start up a new game, I stand up and yell out to everyone <em>&ldquo;I am about to call <code>Yamato</code>!&rdquo;</em> (who our boss assumes is one of my Japanese clients)</p>

<p>Everyone knows that the custom <code>event string</code> (also known as <code>event type</code>) for when everyone listening should play starcraft is <code>"Yamato"</code>. So, ahead of time, Nico, Bob, and Larry listen for my <code>"Yamato"</code> event:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="n">homeButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="s2">&quot;Yamato&quot;</span><span class="o">,</span> <span class="n">startPlayingStarScraft</span><span class="o">);</span>
</span></code></pre></td></tr></table></div></figure>


<p>Now, we may start playing dozens of different games, and I have chosen a different &ldquo;code name&rdquo; as the event string for each type of game:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="n">homeButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="s2">&quot;MarcoPolo&quot;</span><span class="o">,</span> <span class="n">startPlayingAOE</span><span class="o">);</span>
</span><span class='line'><span class="n">homeButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="s2">&quot;Gelinor&quot;</span><span class="o">,</span> <span class="n">startPlayingRuneScape</span><span class="o">);</span>
</span><span class='line'><span class="n">homeButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="s2">&quot;Germany&quot;</span><span class="o">,</span> <span class="n">startPlayingCOD</span><span class="o">);</span>
</span><span class='line'><span class="n">homeButton</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="s2">&quot;Orcish&quot;</span><span class="o">,</span> <span class="n">startPlayingWOW</span><span class="o">);</span>
</span></code></pre></td></tr></table></div></figure>


<h4>Custom Events</h4>

<p>Now, I could create a different type of <code>Event</code> Folder for each type of game, such as <code>StarCraftEvent</code>, <code>RuneScapeEvent</code>, <code>AOEEvent</code> etc.</p>

<p>Each type of event file would have information inside of it, for instance, the <code>StarCraftEvent</code> Folder may have the following properties:
 &ndash; <em>target</em> &ndash; Me, since I&rsquo;m the one &ldquo;dispatching&rdquo; the event
 &ndash; <em>type</em> &ndash; the custom event string, in this case <em>&ldquo;Yamato&rdquo;</em>
 &ndash; <em>map</em> &ndash; the StarCraft map we will be playing in
 &ndash; <em>players</em> &ndash; a list of all players
 &ndash; <em>settings</em> &ndash; the game settings</p>

<p>And our class would look something like this (note that <code>target</code> and <code>type</code> are automatically inherited by the <code>Event</code> since you <code>extend</code> it)</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="kd">public</span> <span class="kd">class</span> <span class="n">StarCraftEvent</span> <span class="kd">extends</span> <span class="n">Event</span>
</span><span class='line'><span class="o">{</span>
</span><span class='line'>    <span class="kd">public</span> <span class="kd">function </span><span class="nf">StarCraftEvent</span><span class="o">(</span><span class="n">the_type</span><span class="o">:</span><span class="kt">String</span><span class="o">,</span> <span class="n">the_map</span><span class="o">:</span><span class="kt">SCMap</span><span class="o">,</span> <span class="n">the_players</span><span class="o">:</span><span class="kt">Array</span><span class="o">,</span> <span class="n">the_settings</span><span class="o">:</span><span class="kt">GameSettings</span><span class="o">)</span>
</span><span class='line'>    <span class="o">{</span>
</span><span class='line'>        <span class="c1">//Since you extend the Event, let the super class know a few more additional details</span>
</span><span class='line'>        <span class="kd">super</span><span class="o">(</span><span class="n">the_type</span><span class="o">);</span>
</span><span class='line'>
</span><span class='line'>        <span class="n">map</span> <span class="o">=</span> <span class="n">the_map</span><span class="o">;</span>
</span><span class='line'>        <span class="n">players</span> <span class="o">=</span> <span class="n">the_players</span><span class="o">;</span>
</span><span class='line'>        <span class="n">settings</span> <span class="o">=</span> <span class="n">the_settings</span><span class="o">;</span>
</span><span class='line'>    <span class="o">}</span>
</span><span class='line'>
</span><span class='line'>    <span class="kd">public</span> <span class="kd">var</span> <span class="n">map</span><span class="p">:</span><span class="kt">SCMap</span><span class="o">;</span>
</span><span class='line'>    <span class="kd">public</span> <span class="kd">var</span> <span class="n">players</span><span class="p">:</span><span class="kt">Array</span><span class="o">;</span>
</span><span class='line'>    <span class="kd">public</span> <span class="kd">var</span> <span class="n">settings</span><span class="p">:</span><span class="kt">GameSettings</span>
</span><span class='line'><span class="o">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>This would be my totally custom made event class! <img alt="" border="0" class="inlineimg" src="http://www.kirupa.com/forum/images/smilies/d_smile.gif" title="Big Smile" /> Perfectly customized for whenever we want to start a StarCraft game, allowing everyone to get the information they need!</p>

<h4>Dispatching the Custom Event</h4>

<p>This is exactly as simple as it was dispatching the <code>"clicked"</code> event:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="c1">//Create the event</span>
</span><span class='line'><span class="kd">var</span> <span class="n">players</span><span class="p">:</span><span class="kt">Array</span> <span class="o">=</span> <span class="o">[</span><span class="n">Andreas</span><span class="o">,</span> <span class="n">Nico</span><span class="o">,</span> <span class="n">Bob</span><span class="o">,</span> <span class="n">Larry</span><span class="o">];</span>
</span><span class='line'><span class="kd">var</span> <span class="n">scEvent</span><span class="p">:</span><span class="kt">StarCraftEvent</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">StarCraftEvent</span><span class="o">(</span><span class="s2">&quot;&lt;u&gt;Yamato&lt;/u&gt;&quot;</span><span class="o">,</span> <span class="n">lostTemple</span><span class="o">,</span> <span class="n">players</span><span class="o">,</span> <span class="n">defaultSettings</span><span class="o">);</span>
</span><span class='line'>
</span><span class='line'><span class="c1">//Dispatch the event (and it&#39;s folder containing all the info)</span>
</span><span class='line'><span class="n">dispatchEvent</span><span class="o">(</span><span class="n">scEvent</span><span class="o">);</span>
</span></code></pre></td></tr></table></div></figure>


<p>That <u>dispatches an event</u> which alerts <u>everyone who is listening</u> that I am about to start up a StarCraft game.</p>

<p>So, Nico, Bob, and Larry run up to my cubicle and I hand them all the <code>StarCraftEvent</code> Folder containing ALL the information they need to join in the game.</p>

<h3>Do you really need to create Custom Events?</h3>

<p>Now I can create a new Custom Event for each and every game we play and that would alright.</p>

<p>But I noticed, no one really reads the information in the <code>Event</code> Folder! I spent good money putting together and printing out all the information for those folders, and no one reads them! They get the file from me, then run back to their own cubicles, fire up the game, and throw the <code>Event</code> Folder directly into the trash.</p>

<p>Surround your pullquote like this {&ldquo; text to be quoted &rdquo;}</p>

<p>Instead, what if I print out a plain old <code>Event</code> Folder? All it says is the <code>target</code> and the <code>type</code>, but if they want more information (which someone once in a while does) they can ask me for it directly.</p>

<p>FORGET about the hassle with the <code>StarCraftEvent</code> class, and just do this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='as3'><span class='line'><span class="kd">var</span> <span class="n">eventFolder</span><span class="p">:</span><span class="kt">Event</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">Event</span><span class="o">(</span><span class="s2">&quot;Yamato&quot;</span><span class="o">);</span>
</span><span class='line'><span class="n">dispatchEvent</span><span class="o">(</span><span class="n">eventFolder</span><span class="o">);</span>
</span></code></pre></td></tr></table></div></figure>


<p>99% of the time. That is all you will ever need. You save a lot of unnecessary work.</p>

<p><strong>You don&rsquo;t always need to create custom <u>Events</u>, usually it is enough just using custom <u>Event Strings</u>.</strong></p>

<p>That is Custom Events 101</p>

<p>Continue to <a href="http://blog.iqandreas.com/actionscript/understanding-the-as3-event-system/part-3-easy-event-bubbling">Part #3 &ndash; Easy Event Bubbling</a></p>
]]></content>
  </entry>
  
</feed>
