<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dispatchEvent() Blog™ &#187; Tutorial</title>
	<atom:link href="http://dispatchevent.org/category/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://dispatchevent.org</link>
	<description>Collective thoughts on Flash and Flex programming</description>
	<lastBuildDate>Fri, 19 Mar 2010 00:16:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using ant for Flex &#8211; a no B.S. guide &#8211; Part 4 of 4</title>
		<link>http://dispatchevent.org/mims/ant-for-flex-part-4/</link>
		<comments>http://dispatchevent.org/mims/ant-for-flex-part-4/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 03:31:43 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[flashbuilder]]></category>
		<category><![CDATA[flexbilder]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=771</guid>
		<description><![CDATA[
Part 1
Part 2
Part 3
Part 4

Now that you&#8217;ve been through 3 exhaustive tutorials on ant for flex, it&#8217;s time to use your knowledge you&#8217;ve gained to turn your back on the built-in Flex compiler and switch to ant for your builds. This part applies to FlexBuilder (and FlashBuilder) users only although it may apply if you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://dispatchevent.org/mims/ant-for-flex-part-1/">Part 1</a></li>
<li><a href="http://dispatchevent.org/mims/ant-for-flex-part-2/">Part 2</a></li>
<li><a href="http://dispatchevent.org/mims/ant-for-flex-part-3/">Part 3</a></li>
<li>Part 4</li>
</ul>
<p>Now that you&#8217;ve been through 3 exhaustive tutorials on ant for flex, it&#8217;s time to use your knowledge you&#8217;ve gained to turn your back on the built-in Flex compiler and switch to ant for your builds. This part applies to FlexBuilder (and FlashBuilder) users only although it may apply if you&#8217;re using some other eclipse-based plugin. If you&#8217;re using another program like TextMate or Flash CSx, you can skip this article.<br />
<span id="more-771"></span></p>
<h3>Replacing the default builder with your ant tasks</h3>
<p>The rest of this article will show you how to use your ant build script to perform the building actions found in FlashBuilder.</p>
<p>In FlashBuilder, the following building actions can be executed</p>
<ul>
<li><strong>Build Project &#8211; </strong>Occurs when the user manually builds the project.</li>
<li><strong>Build Automatically &#8211; </strong>When the option is checked in the Project menu, the code is automatically build when you save a file. Usually incrementally.</li>
<li><strong>Clean</strong> &#8211; &#8216;cleans&#8217; the project folder by doing a complete, non-incremental build and removing temporary files.</li>
</ul>
<p>These actions are all called by various actions and handled by one or more <em>builders</em>. In terms of the eclipse SDK, a builder is an XML file that describes how the various build actions will be executed. In FlashBuilder, all of these are set up to use the Flex &#8220;builder&#8221; by default. You can add new customized builders to supplement these build actions. You can also deactivate the default builder an just use your ant builds instead <strong>but you will lose the ability to see inline errors in your code</strong>.</p>
<p>In order for this to work however, you need to start out with some solid, well-tested ant tasks.</p>
<h4>Step 1 &#8211; Create the appropriate ant targets</h4>
<p>Create a target in your build.xml for each of the actions listed above. Call each target &#8220;build&#8221;, &#8220;autoBuild&#8221;, and &#8220;clean&#8221;. You can probably start with the &#8220;build&#8221; target and reuse it for the other two. To write an incremental build target (used for the build-automatically action) there is an example in<a href="http://dispatchevent.org/mims/ant-for-flex-part-2/"> Part 2</a> of this article.</p>
<p>Before moving on, please test your build script thoroughly to be sure there are no errors and that your files are compiling correctly.</p>
<p>Note, I&#8217;m not going to go into the details here about exactly how to write your ant script. If you&#8217;re considering switching to ant as your primary builder then A) your project has special needs that need to be addressed by a custom build script and I don&#8217;t know what those needs are and B) you need to know what you&#8217;re doing with ant before completely abandoning FlashBuilder&#8217;s defaults. I will say, save the fancy stuff for your release build targets and do incremental builds by default since you&#8217;ll be running these scripts quite a lot.</p>
<h4>Step 2 &#8211; Create a builder for your ant build script</h4>
<ol>
<li>Open the properties for the project you want to edit. <strong>Project -&gt; Properties</strong></li>
<li><strong>Select the Builders item</strong> in the left menu. You will see that the default builder &#8220;Flex&#8221; is already set up.</li>
<li><strong>Click the New&#8230; button</strong>. A dialog will come up with templates for the new builder.</li>
<li><strong>Choose the &#8220;Program&#8221; type</strong>. (On my configuration, I see an option for &#8220;Ant Builder&#8221; also which is what I should probably be using, however, I haven&#8217;t gotten it to work yet and it doesn&#8217;t seem to generate any specific errors when it fails so I gave up and went with Program. If you know how to fix this, let me know!)</li>
<li><strong>Name the builder &#8220;flexAntBuilder&#8221;</strong></li>
<li><strong>Set the location field to the ant binary you&#8217;re using.</strong> If you&#8217;re not sure where the binary is located, you can use the command <code>which ant</code> in the command line. Mine is at <code>/usr/bin/ant</code></li>
<li><strong>Set the Working directory to your project&#8217;s home directory</strong>. If you&#8217;re not sure, browse to it.</li>
<li><strong>In the arguments field, enter the name of the target you want to run. </strong>In this case <code>build</code>.</li>
<li><strong>Optional: Click on the Refresh tab.</strong> Here you can chose whether to refresh the files in your workspace when the build completes.</li>
<li><strong>Click on the Build Options tab. </strong>Here, under the &#8220;Run the Builder:&#8221; heading near the bottom, is where you&#8217;re going to set the properties that determine when this particular task is run. For the &#8216;build&#8217; target, <strong>uncheck everything except &#8220;During Manual Builds&#8221;.</strong>
<ul>
<li>For your &#8220;autoBuild&#8221; target, you&#8217;re going to uncheck everything except &#8220;During auto builds&#8221;</li>
<li>For your &#8220;clean&#8221; target, you&#8217;re going to uncheck everything except &#8220;After a clean&#8221;</li>
</ul>
</li>
<li><strong>Repeat steps 1-10 for the other two targets.</strong></li>
<li>When all targets are added,<strong> </strong><strong>optionally</strong><strong> uncheck the &#8220;flex&#8221; builder from the builders menu in your project properties to use the ant tasks exclusively.</strong> Now your ant scripts will be used instead of the flex builder.</li>
</ol>
<p>That&#8217;s it! Be sure to test things and make sure you&#8217;re not getting any errors.</p>
<h4>What to expect from here</h4>
<p>So you&#8217;ve unchained yourself from the system and are using your ant scripts to build your project. Congratulations, you&#8217;re a huge nerd! From this point on, changing the compile settings in the Project Properties dialog (like the build path) may be ineffective. You&#8217;ll need to make changes to your build path in the ant file.</p>
<p>The results from your builds will appear in the Console view. Here you can see the progress of builds and check for errors in the code. As I mentioned before, if you deactivate the flex builder you won&#8217;t get inline errors in your code any longer.</p>
<p>Finally, adding the new builders will create a new invisible folder in your project&#8217;s root folder called .externalToolBuilders where your builder definitions will be kept. You don&#8217;t need to do anything with this folder, but be aware that it&#8217;s there.</p>
<p>That concludes this 4 part epic post about ant tasks for flex! I hope you found it useful. If you have anything to add, please post comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/ant-for-flex-part-4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using ant for Flex &#8211; a no B.S. guide &#8211; Part 3 of 4</title>
		<link>http://dispatchevent.org/mims/ant-for-flex-part-3/</link>
		<comments>http://dispatchevent.org/mims/ant-for-flex-part-3/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 01:31:16 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[flexbuilder]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=763</guid>
		<description><![CDATA[
Part 1
Part 2
Part 3
Part 4

This third installment talks about tips and tricks for using ant with version control systems.

Defining external properties for each user
Since not everyone&#8217;s machine is the same and letting everyone build a project is a major reason to use ant, it&#8217;s good to avoid hard coding paths to files within your build.xml [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://dispatchevent.org/mims/ant-for-flex-part-1/">Part 1</a></li>
<li><a href="http://dispatchevent.org/mims/ant-for-flex-part-2/">Part 2</a></li>
<li>Part 3</li>
<li><a href="http://dispatchevent.org/mims/ant-for-flex-part-4/">Part 4</a></li>
</ul>
<p>This third installment talks about tips and tricks for using ant with version control systems.<br />
<span id="more-763"></span></p>
<h3>Defining external properties for each user</h3>
<p>Since not everyone&#8217;s machine is the same and letting everyone build a project is a major reason to use ant, it&#8217;s good to avoid hard coding paths to files within your build.xml file. As such, I use a lot of &lt;property&gt; tags to set up paths and such. But you also don&#8217;t want to have several people constantly editing your build.xml because it could get broken or out of sync. Oh no! What do we do!?</p>
<p>Luckily, ant lets you define a set of properties in an external file. This is a simple text file containing name=value pairs and commented using #. By default, the recommended filename is build.properties.  Here&#8217;s an example:<br />
<script src="http://gist.github.com/234318.js"></script></p>
<h4>build.properties and version control</h4>
<p>If you&#8217;re working with multiple people, you are probably using a version control system like svn. If you are and you want to avoid people accidentally checking in a build.properties file there are a couple of simple tricks. First, create a copy of build.properties and call it <em>built.properties.template</em> and check that into the repository. Then each user can make a local copy called build.properties. You can also add build.properties to the ignore list for your folder using SVN so that noone will accidentally check it in. Run <code>svn pe svn:ignore</code> and add build.properties to the list. Finally, if you need to make sure that your users have a local copy of  build.properties, <em>there&#8217;s a task for that!™</em> <script src="http://gist.github.com/234320.js"></script></p>
<h3>Adding SVN tasks</h3>
<p>As I work with SVN quite a lot, I found that including SVN in my builds can be quite useful. For example you could:</p>
<ul>
<li>Update your working copy when doing a clean build.</li>
<li>Check in a release build automatically.</li>
<li>Export your source code without those pesky .svn files to be included in a zip file.</li>
<li>Include the revision number of the working copy as a constant definition in the code using <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html#246171">conditional compiliation</a>.</li>
</ul>
<p>To do this, you&#8217;ll need to first download the SVN tasks for ant. They can be found on the <a href="http://subclipse.tigris.org/svnant.html">Tigris.org</a> website. Please note, that these tasks are a part of <a href="http://subclipse.tigris.org/">SubClipse</a>, which is a free interface for working with Subversion from within Eclipse. I don&#8217;t know if the tasks will work without subclispe, but if you haven&#8217;t used it, I&#8217;d definitely recommend trying it out anyway.  By the way, if you use CVS, there are already tasks included in ant.  Once they&#8217;re downloaded, add the task .jars to the libs/ant folder in your project. You&#8217;ll need to use another &lt;typedef&gt; tag in your build script to get these to work. Here&#8217;s an example snippet that simply runs an update on the working copy. You can see all the available commands in the <a href="http://subclipse.tigris.org/svnant/svn.html">svnant documentation</a>.  <script src="http://gist.github.com/234312.js"></script></p>
<p>That&#8217;s it for part 3. In <a href="http://dispatchevent.org/mims/ant-for-flex-part-4/">Part 4</a>, I&#8217;ll talk about setting up a builder for your ant file in FlashBuilder.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/ant-for-flex-part-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using ant for Flex &#8211; a no B.S. guide &#8211; Part 2 of 4</title>
		<link>http://dispatchevent.org/mims/ant-for-flex-part-2/</link>
		<comments>http://dispatchevent.org/mims/ant-for-flex-part-2/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 01:20:37 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[flexbuilder]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tasks]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=760</guid>
		<description><![CDATA[
Part 1
Part 2
Part 3
Part 4

In this part, I get more nitty-gritty about working with flex&#8217;s ant tasks.

Using the flex ant tasks
I spent quite a lot of time making tweaks to get my scripts to use the Flex tasks and hopefully, now you won&#8217;t have to. In the end, there&#8217;s very little benefit to using the [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://dispatchevent.org/mims/ant-for-flex-part-1/">Part 1</a></li>
<li>Part 2</li>
<li><a href="http://dispatchevent.org/mims/ant-for-flex-part-3/">Part 3</a></li>
<li><a href="http://dispatchevent.org/mims/ant-for-flex-part-4/">Part 4</a></li>
</ul>
<p>In this part, I get more nitty-gritty about working with flex&#8217;s ant tasks.<br />
<span id="more-760"></span></p>
<h3>Using the flex ant tasks</h3>
<p>I spent quite a lot of time making tweaks to get my scripts to use the Flex tasks and hopefully, now you won&#8217;t have to. In the end, <strong>there&#8217;s very little benefit to using the official Flex ant tasks over using a generic &lt;exec&gt; task</strong> (a type of ant task that simply runs an executable file with nested &lt;arg&gt; tags for command line arguments) <strong>and if you&#8217;re having trouble with them, I&#8217;d recommend abandoning the flex tasks and using $lt;exec&gt;</strong>. The main thing I had trouble with was getting the &lt;taskdef&gt; tag to work correctly.</p>
<p>For those new to ant, a &lt;taskdef&gt; tag is a required tag that defines a third-party ant task within the build.xml file. It associates a task name with a .jar file (compiled from the java code for the task). In the case of flex tasks, the java file is typically located within your flexbuilder sdk directory. On my mac, that&#8217;s here:</p>
<p>/Applications/Adobe\ Flash\ Builder\ Plug-in\ Beta\ 2/sdks/${SDK_VERSION}/ant/lib</p>
<p>Where ${SDK_VERSION} is your target sdk version (e.g. 4.0.0). There are a few ways to load additional tasks into your build.xml file. All of them require you to reference the .jar&#8217;s location somehow and then define a new task using &lt;taskdef&gt;.</p>
<ol>
<li><strong>Copy the .jar file for the task into ant&#8217;s lib directory.</strong> I don&#8217;t personally like this option because it makes it very difficult to switch between different versions of the sdk. Also, it requires all users of the script to copy the files on their local machines. (You can also add it to ~/<code>.ant/lib </code>to control the libraries on a user level)</li>
<li><strong>Reference the .jar file&#8217;s location using a command line argument -lib</strong>. Even worse than the first option since it requires each user to add the library manually every time the build script is run.</li>
<li><strong>Include the .jar&#8217;s location inside the build script.</strong> It took me a long time to figure this one out since I didn&#8217;t see it in the manual for ant, but it&#8217;s certainly my preferred method for adding tasks. It allows you to keep everything self contained within the build.xml so changing the location of the .jar is as simple as setting a property in the build script.</li>
</ol>
<p>When using the 3rd option, you then have the question of where is the best place to put the .jar files you want to link to. There are two options that make sense to me.</p>
<ol>
<li>The best place to put non-core tasks required by your build (for a Flex project) is in ${project_home}/libs/ant. This allows you to check your tasks into a repository along with your other referenced files (like .swc files).</li>
<li>Optionally, for the flex tasks you could reference the .jar file directly in the sdk folder. Use this option if the version number of the SDK doesn&#8217;t matter. If it does matter, use the first option. I use this option in my snippet below.</li>
</ol>
<h4>Linking to the official Flex ant tasks</h4>
<p>Here&#8217;s a sample of my flex task definition along with some path definitions that point to various parts of Flex. I said this was a no B.S. guide so if you paste this snippet into your build script, you should be able to use the Flex tasks.<br />
<script src="http://gist.github.com/233455.js?file=FlexAntTaskDefs.xml"></script></p>
<h4>Using the tasks</h4>
<p>Now we have the &lt;typedef&gt; in place and we can actually create a task to compile something. Again, I&#8217;m not going to go into all the details of what <a href="http://ant.apache.org/manual/using.html#targets">targets</a> are all about or go into all the details about the <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_22.html">flex compilers</a>. There are plenty of other tutorials about that. Instead, I&#8217;ll show you a basic target to build an mxml file that is adequate for 95% of projects. Note: you may need to edit the properties defined in these scripts so that they point to the right paths for your project.</p>
<p><script src="http://gist.github.com/234291.js"></script> The toughest part about using these tasks is the seemingly arbitrary words that they expect for the attribute names of some tags (like using <em>path-element</em> in the &lt;source-path&gt; tag but <em>dir</em> in the &lt;library-path&gt; tag). Now the same but this time building a library SWC.  <script src="http://gist.github.com/234288.js"></script></p>
<h4>Making an incremental build</h4>
<p>By default, FlexBuilder uses incremental builds when compiling your source code (except for clean builds). This is a very useful feature of the compiler because it saves time by only compiling the parts of your code that have changed since the last build. You can create an incremental build simply using ant by defining a second task that adds a flag  for incremental building like so. Note that  allows you to run other targets from within a target.</p>
<p><script src="http://gist.github.com/234287.js"></script></p>
<h4>What about ASDocs?</h4>
<p>Even though there are tasks for asc, compc, mxmlc, and generating HTML wrappers, they didn&#8217;t bother to include an asdoc task (actually, they did in Flex SDK 4.0.0). But that&#8217;s okay! As I hinted at earlier, you can still use the  task to run this (as you can for all the other commands) and not only that, it&#8217;s way easier to set up than the official flex tasks! In fact, the only reason that I can think of to use the flex tasks is that they would automatically  use the windows or mac version of the executable depending on your platform. Here&#8217;s an example for asdoc.  <script src="http://gist.github.com/234294.js"></script></p>
<p>That concludes part 2. In <a href="http://dispatchevent.org/mims/ant-for-flex-part-3/">Part 3</a>, I&#8217;ll talk about working with version control systems in ant.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/ant-for-flex-part-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using ant for Flex &#8211; a no B.S. guide &#8211; Part 1 of 4</title>
		<link>http://dispatchevent.org/mims/ant-for-flex-part-1/</link>
		<comments>http://dispatchevent.org/mims/ant-for-flex-part-1/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 01:15:52 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[flashbuilder]]></category>
		<category><![CDATA[flexbuilder]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[tasks]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=746</guid>
		<description><![CDATA[
After spending hours wrangling with my ant build script and finally making everything work correctly, I am convinced of two things:

ant is a very powerful tool for compiling code but it can also do so much more.
The support for ant for flex online is abysmally frustrating.

So, I&#8217;d love to share with you some of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dispatchevent.org/wp-content/uploads/2009/11/QueenAnt.jpg"><img class="alignnone size-full wp-image-784" title="ant" src="http://dispatchevent.org/wp-content/uploads/2009/11/QueenAnt.jpg" alt="About to burst with build targets" width="159" height="159" /></a></p>
<p>After spending hours wrangling with my ant build script and finally making everything work correctly, I am convinced of two things:</p>
<ol>
<li><a href="http://ant.apache.org/manual/index.html">ant</a> is a very powerful tool for compiling code but it can also do so much more.</li>
<li>The support for ant for flex online is abysmally frustrating.</li>
</ol>
<p>So, I&#8217;d love to share with you some of the tips I&#8217;ve picked up after tweaking my script to the point where it finally worked!</p>
<h3>Introducing ant</h3>
<p>First of all, let me introduce the basics of what ant is. I couldn&#8217;t really say it better than the thousands of nameless editors of <a href="http://en.wikipedia.org/wiki/Apache_Ant">WikiPedia</a>.</p>
<blockquote><p><strong>Apache Ant</strong> is a software tool for <a title="Build automation" href="http://en.wikipedia.org/wiki/Build_automation">automating software build</a> processes. It is similar to <a title="Make (software)" href="http://en.wikipedia.org/wiki/Make_%28software%29">Make</a> but is implemented using the <a title="Java (programming language)" href="http://en.wikipedia.org/wiki/Java_%28programming_language%29">Java</a> language, requires the Java platform, and is best suited to building Java projects.</p>
<p>The most immediately noticeable difference between Ant and Make is that Ant uses <a title="XML" href="http://en.wikipedia.org/wiki/XML">XML</a> to describe the build process and its dependencies, whereas Make has its Makefile format. By default the XML file is named <code>build.xml</code>.</p>
<p>Ant is an <a title="Apache Software Foundation" href="http://en.wikipedia.org/wiki/Apache_Software_Foundation">Apache</a> project. It is <a title="Open source software" href="http://en.wikipedia.org/wiki/Open_source_software">open source software</a>, and is released under the <a title="Apache Software License" href="http://en.wikipedia.org/wiki/Apache_Software_License">Apache Software License</a>.</p></blockquote>
<p>So in short, ant lets you use an XML based script to run a series of commands typically used to build software projects. It was originally designed to be &#8220;for Java, in Java&#8221; but it&#8217;s popularity and ease of use has created interest beyond the Java community. For flex, ant can be used for compiling ActionScript and Flex projects into SWFs, creating SWC files, generating documentation with ASDocs, and other actions associated with compiling.</p>
<p>There are a lot of great tutorials online that can cover the basics of how ant works so I&#8217;m not going to go into a general overview in this article. Instead, I&#8217;m going to try to focus on some of the practical aspects of getting a build set up when working with Flex. However, here are some links to the <a href="http://ant.apache.org/manual/">official ant documentation</a> some helpful tutorials for the basics:</p>
<p><a href="http://www.allapplabs.com/ant/ant_basics.htm">Ant Basics tutorial</a></p>
<p><a href="http://flexblog.faratasystems.com/2006/12/05/intro-to-building-and-deploying-flex-applications-with-ant">Another basics tutorial (this time for Flex)</a></p>
<p><a href="http://livedocs.adobe.com/flex/3/html/help.html?content=anttasks_1.html">Official Flex documentations</a></p>
<p><a href="http://wiki.apache.org/ant/AntTasks">Ant Folklore</a></p>
<p>After the jump, I&#8217;ll get into some of the ways that ant can be useful for Flash and Flex projects.<br />
<span id="more-746"></span> </p>
<h4>Applications for Flex users</h4>
<p>Is ant right for you? It depends. For most cases, using the standard Run and Debug functions in FlashBuilder or Flash will be completely sufficient. However, if you work on a large development team or on a project with a complicated build process, it might save the group a lot of headache. Here&#8217;s a list of situations where I think Flex ant tasks can be helpful.</p>
<ul>
<li>Whenever your project requires you to make adjustments to the standard build process. For example, when you need to add additional flags to your compiler string.</li>
<li>For Flex projects that are distributed widely, e.g. open source projects, where the configuration of the users&#8217; dev environment is unknown. Build scripts allow users of various versions of FlexBuilder, FDT, or Flex SDK users on different operating systems to all be able to compile a project with more or less the same settings.</li>
<li>If running or building your project requires you to configure options in the command line or to run a local server.</li>
<li>For building release versions of an app and for deploying your app. For example, compiling, zipping and copying an app to a server using FTP.</li>
<li>When you&#8217;re a total nerd and you want to use ant just so you can say you did it.</li>
</ul>
<h3>Beyond Compiling</h3>
<p>One of the main benefits of using ant is that I think many people are unaware of is that it can be  used for many things beyond running compilers. For example, in <a href="http://code.google.com/p/kitchensynclib/">KitchenSync</a>, I use a <a href="http://code.google.com/p/kitchensynclib/source/browse/trunk/build.xml">build script</a> to create a temp folder, compile a SWC file into the temp folder, create an SVN export of the source folder into the temp folder, zip the source and SWC and name it with the current version number, then delete the temp folder.</p>
<p>There are loads of <a href="http://ant.apache.org/manual/coretasklist.html">core tasks</a> that are already defined within the ant library. They handle all types of common actions in the command line. There are even additional <a href="http://ant.apache.org/manual/optionaltasklist.html">optional tasks</a> that add higher-level functionality like copying files to a server using SSH or validating an XML file. Finally, additional tasks can be added simply by creating a new Java class that is a subclass of <code>org.apache.tools.ant.Task</code>. You probably won&#8217;t do this yourself, but there are a number of third-party programs that have created &#8216;plug-in&#8217; tasks for ant such as SVN.</p>
<p>Once Flex projects became larger and more complex, many users began to look for more customizable options and began using ant. A couple of years back, Adobe released some official ant tasks which can now be found bundled in every version of the Flex SDK. However, as I said before the documentation of exactly how to get these tasks running is vague at best.</p>
<p>In <a href="http://dispatchevent.org/mims/ant-for-flex-part-2/">part 2</a>, I&#8217;ll talk about the details of getting flex ant tasks running.</p>
<ul>
<li>Part 1</li>
<li><a href="http://dispatchevent.org/mims/ant-for-flex-part-2/">Part 2</a></li>
<li><a href="http://dispatchevent.org/mims/ant-for-flex-part-3/">Part 3</a></li>
<li><a href="http://dispatchevent.org/mims/ant-for-flex-part-4/">Part 4</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/ant-for-flex-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using XML Schemas in Eclipse / FlexBuilder</title>
		<link>http://dispatchevent.org/mims/using-xml-schemas-in-eclipse-flexbuilder/</link>
		<comments>http://dispatchevent.org/mims/using-xml-schemas-in-eclipse-flexbuilder/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 05:00:16 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[flexbuilder]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml-schema]]></category>
		<category><![CDATA[xsd]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=626</guid>
		<description><![CDATA[UPDATE: After reading the entry by Misprintt on the SchemaManager and XMLDecoder more thoroughly, I felt the need to tell you all to go check it out! This is a very powerful undocumented feature of Flex (why undocumented?) that could potentially save loads of time on a larger project. Along with the rest of this [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE:</strong> After reading the <a href="http://blog.misprintt.net/?p=192">entry by Misprintt on the SchemaManager and XMLDecoder</a> more thoroughly, I felt the need to tell you all to go check it out! This is a very powerful undocumented feature of Flex (why undocumented?) that could potentially save loads of time on a larger project. Along with the rest of this article, you could automate the parsing of your XML files into bindable model classes with ease.</p>
<p><a href="http://www.w3schools.com/Schema/default.asp">XML-Schema</a> (.XSD extension) are documents used to describe the format of XML files. They are similar to DTD (Document type declaration) files but much more powerful.</p>
<p><a href="http://dispatchevent.org/wp-content/uploads/2009/02/picture-1.png"><img class="alignnone size-full wp-image-633" title="xsd editor" src="http://dispatchevent.org/wp-content/uploads/2009/02/picture-1.png" alt="xsd editor" width="435" height="355" /></a></p>
<p>While working on some XML documents for a Flash site, I stumbled across the XML-Schema editor for Eclipse. The editor shows the XSD as a graphical representation of the model that you&#8217;re editing that looks similar to a UML class diagram.</p>
<p><a href="http://wiki.eclipse.org/index.php/Introduction_to_the_XSD_Editor">Here&#8217;s a great article on how it works.</a></p>
<h3><span id="more-626"></span>Benefits of using XSD</h3>
<p>As I said, XSD allows you to define the format of your XML document but with much more detail that DTD.</p>
<ul>
<li>XSD allows you to type your data (integers, strings, booleans) so that you can better predict what format the xml will be</li>
<li>It allows the creation of custom types which gives it an object oriented aspect</li>
<li>You can use all kinds of restrictions for what kind of content can appear within a tag including the number of elements, whether values are required or not, you can even use regular expressions to limit the acceptable values. This is very nice when you&#8217;re working with a 3rd party who is generating the XML data.</li>
<li>Using an XSD file can allow you to automate the validation of an XML file&#8217;s format</li>
</ul>
<p>Once you&#8217;ve created your XSD file, you can use the new XML document wizard to create an XML file that links to your schema file. The wizard will automatically populate the XML document with valid data! Furthermore, as you edit the XML file you will get warnings and errors if you go outside the formatting requirements defined in the XSD. For example, if you define a tag &lt;description&gt; as having a maximum length of 128, you will see a visual error if your tag contains more than 128 characters. It&#8217;s a great way to forsee problems as you write them.</p>
<p><span style="text-decoration: line-through;">I hope in the future to write some kind of tool to parse XML based on an XSD file in flash.</span> Apparently, Adobe had created an undocumented Flex feature to validate XML against XSD. <a href="http://blog.misprintt.net/?p=181">Via Misprintt</a></p>
<h3>Installing the XML extensions</h3>
<p>Unfortunately, the editor is not installed by default and nstalling software in Eclipse is not very intuitive. I&#8217;ve done my best to describe the process here but if you need further help, <a href="http://dispatchevent.org/mims/pimp-my-clipse-a-list-of-must-have-eclipse-plug-ins-for-flexflash-development/">check this entry</a>.</p>
<ol>
<li>Open Eclipse or FlexBuilder</li>
<li>Go to Help&gt;Software Updates&#8230; ( &gt; Find and Install for Eclipse 3.3)<br />
<a href="http://dispatchevent.org/wp-content/uploads/2009/02/softwareupdate.png"><img class="alignnone size-full wp-image-630" title="softwareupdate" src="http://dispatchevent.org/wp-content/uploads/2009/02/softwareupdate.png" alt="softwareupdate" /></a></li>
<li>Make sure you have the <a href="http://www.eclipse.org/europa/">Europa</a> or <a href="http://www.eclipse.org/ganymede/">Ganymede</a> update sites in the list of update sites:
<pre style="margin: 0em;">Eclipse 3.4 users:
<a class="external free" title="http://download.eclipse.org/releases/ganymede/" rel="nofollow" href="http://download.eclipse.org/releases/ganymede/">http://download.eclipse.org/releases/ganymede/</a>

<a href="http://download.eclipse.org/releases/europa/site.xml">http://download.eclipse.org/releases/europa/site.xml</a></pre>
</li>
<li>Select the XML and XSD extensions in this screenshot. In Eclipse 3.4 you can search for them, in 3.3 you will have to look through the packages for them manually.<a href="http://dispatchevent.org/wp-content/uploads/2009/02/xmlextensions.png"><img class="alignnone size-full wp-image-629" title="xmlextensions" src="http://dispatchevent.org/wp-content/uploads/2009/02/xmlextensions.png" alt="xmlextensions" width="400" /></a></li>
<li>Restart Eclipse after the install is complete</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/using-xml-schemas-in-eclipse-flexbuilder/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Downsampling Flash &#8211; Converting AS3 to AS2</title>
		<link>http://dispatchevent.org/mims/converting-as3-to-as2/</link>
		<comments>http://dispatchevent.org/mims/converting-as3-to-as2/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 01:03:32 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=565</guid>
		<description><![CDATA[I recently came across a situation where I was forced to convert a working project in Flash 9 AS3 to Flash 8 AS2. I wanted to share some of my experiences to help other weary programmers in the same predicament.

Before I begin, I must stress to you, if there is any way you can avoid [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across a situation where I was forced to convert a working project in Flash 9 AS3 to Flash 8 AS2. I wanted to share some of my experiences to help other weary programmers in the same predicament.</p>
<p><span id="more-565"></span></p>
<p>Before I begin, I must stress to you, <strong>if there is any way you can avoid downgrading your code, you should avoid it!</strong> If it&#8217;s a matter of making two systems communicate, there are countless reasons that it would be better to upgrade your code from AS2 to AS3. There are even ways to host your AS2 code in an AS3 wrapper. In my case, an important requirement (that the deliverable absolutely must be AS2) was left out of the original scope of work due to a misunderstanding but anything that doesn&#8217;t cause project stoppage should be considered carefully.</p>
<p>I must also preface this article by reminding the reader that there is no 1-to-1 conversion from AS3 to AS2 (nor the other way around). There are loads of features added to Flash Player 9 that simply don&#8217;t exist in Player 8. Some things you&#8217;ll be able to convert with a simple find and replace. Some things you&#8217;ll need to re-create in AS2 or re-think completely. Some things you just won&#8217;t be able to do. This article only covers the stuff I ran across while converting my files and is by no means comprehensive. However, I hope it gives you a good starting point to work from.</p>
<p><strong>Converting the document class </strong></p>
<p>Since you&#8217;re a smart, cool AS3 programmer with a good sense of humour, I know you use a document class in your FLA files or a main application class for your FlexBuilder project. Right? Good. Of course, AS2 does not support document classes and all code must be run from the timeline. You have a couple of options here. You could move your document class to the timeline and remove the class specific portions of the code. Perhaps a quicker and easier solution is to modify your document class to take a reference to the root. So you have something like this on the first frame&#8230;</p>
<pre>var documentClass:MyDocumentClass = new MyDocumentClass(this);</pre>
<p>Just keep in mind that your document class will need to store a reference to the root that&#8217;s passed in as well as make references to things that were on the stage. For example&#8230;</p>
<pre>public function MyDocumentClass(mc:MovieClip) {
   this._mc = mc;
   this.thingOnStage = _mc.thingOnStage;
}</pre>
<p><strong>Cleaning up syntax errors</strong></p>
<p>The first step to take once you can compile your code is to run it and fix each compile time error one at a time. To save you the trouble of some of the more common ones I found, I created this list of common syntax problems.</p>
<p><strong>Search and replace:</strong></p>
<ul>
<li>void -&gt; Void</li>
<li>int and uint -&gt; Number</li>
<li>DisplayObject, DisplayObjectContainer, Sprite -&gt; MovieClip</li>
<li>public class -&gt; class</li>
<li>internal -&gt; public</li>
<li>protected -&gt; private</li>
<li>override -&gt; (nothing)</li>
<li>mouseEnabled -&gt; enabled</li>
<li>[obj] as [type] -&gt; [type]([obj])</li>
<li>[obj] is [type] -&gt; [obj] instanceof [type]</li>
<li>const -&gt; var (or optionally, to implicit getter)</li>
<li>Add underscores before MovieClip variables. e.g.: x, scaleY, alpha -&gt; _x, _yscale, _alpha including:
<ul>
<li>alpha -&gt; _alpha</li>
<li>x,y -&gt; _x, _y</li>
<li>scaleX,Y -&gt; _xscale, _yscale</li>
<li>mouseX,Y -&gt; _xmouse, _ymouse</li>
<li>visible -&gt; _visible</li>
<li>currentFrame -&gt; _currentFrame</li>
<li>totalFrames -&gt; _totalframes</li>
</ul>
</li>
</ul>
<p><strong>Add:</strong></p>
<ul>
<li>import statements for classes within the same package (not required in AS3)</li>
</ul>
<p><strong>Remove:</strong></p>
<ul>
<li>import statements for AS3 packages (e.g. flash.display.* )</li>
</ul>
<p><strong>Convert:</strong></p>
<ul>
<li> _xscale, _yscale, _alpha &#8211; Convert from decimal to integer (0.2 becomes 20).</li>
<li> Convert Timer to setInterval</li>
<li> Convert Loader to MovieClipLoader</li>
<li> Remove package declaration but copy the package name and put it before the class name. Also remove closing } from the end of the file.<br />
e.g. :</p>
<pre>package com.mysite.package {
	public class Foo {
	 	//...
	}
}</pre>
<p>becomes</p>
<pre>class com.mysite.package.Foo {

	//...

}</pre>
</li>
</ul>
<p><strong>Other tips</strong></p>
<p>Events are a huge part of AS3 development and Player 9 supports a fully event-driven development style. Unfortunately, AS2 is heavily lacking in this department and while events can be recreated in AS2, it lacks method closures and bubbling that make AS3 so nice. To downgrade, I did two things. First, I recreated the event dispatcher in as2 and second, I made heavy use of event callbacks and the Delegate class.</p>
<p><strong>com.mimswright.events</strong></p>
<p>In order to change as little of the event code as possible, I looked back to previous AS2 projects where I had used <a href="http://dannypatterson.com">Danny Patterson</a>&#8217;s EventBroadcaster classes. These classes worked roughly the same as the EventDispatcher class in AS3. I took the liberty of brushing up the code and making it look as much like the AS3 EventDispatcher as I could. I&#8217;m making it freely available for use.</p>
<p><a href="http://dispatchevent.org/wp-content/uploads/2009/01/as2eventdispatcher.zip">as2eventdispatcher</a></p>
<p><strong>event callbacks</strong></p>
<p>Most of the events you&#8217;ll probably be using must be triggered by callbacks in AS2. That is, you define a function that gets called when an event takes place like</p>
<pre>onMouseMove = function ():Void {
   //do something
}</pre>
<p>Keep in mind that in AS2 there are no method closures as there are in AS3. That is, a function isn&#8217;t necessarily executed in the scope that it exists in. In even simpler terms, a function doesn&#8217;t know what object it&#8217;s associated with. Because of this, code such as <code>button.onRelease = object.handleClick;</code> executes the <code>handleClick</code> function from the <code>button</code> context and my not work properly. Fortunately, AS2 code can make use of the <code>mx.utils.Delegate</code> class &#8211; specifically, the <code>Delegate.create()</code> method. This artificially maintains the context in which the function was supposed to be called. So your code should look like <code>button.onRelease = mx.utils.Delegate.create(object, object.handleClick);</code></p>
<p>I hope this has been a helpful start for you poor souls who are faced with the challenge of down-converting code. Good luck to you and feel free to add your experiences to the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/converting-as3-to-as2/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Tip: Adding version checking to your external code library</title>
		<link>http://dispatchevent.org/mims/version-checking/</link>
		<comments>http://dispatchevent.org/mims/version-checking/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 18:14:33 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[KitchenSync]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=446</guid>
		<description><![CDATA[Since version 1.0 of a code library that I&#8217;m sure you&#8217;re tired of me talking about came out, I have been making steady updates, some of which break legacy code. I was also having trouble keeping track of which version of the library a particular demo was written for. In order to make sure that [...]]]></description>
			<content:encoded><![CDATA[<p>Since version 1.0 of <a href="http://kitchensynclib.googlecode.com" target="_blank">a code library that I&#8217;m sure you&#8217;re tired of me talking about</a> came out, I have been making steady updates, some of which break legacy code. I was also having trouble keeping track of which version of the library a particular demo was written for. In order to make sure that the new code library doesn&#8217;t cause unpredictable results for the old implementations I added a version check to the main class.</p>
<p>This version check is very simple. It checks a version number in the client code against a version number of the library (or external classes) when the main class of the library is initialized. It is also completely optional (so average users don&#8217;t need to mark up their code with version numbers).</p>
<p>Here&#8217;s an example:</p>
<p>Say you normally initialize your library using:</p>
<pre lang="actionscript3">MyLibrary.initialize();</pre>
<p>Which calls the initialize method:</p>
<pre lang="actionscript3">public static function initialize():void {
   // initialize library here
}</pre>
<p>If the external code changes unexpectedly (say through an SVN update) this could cause problems that are difficult to trace. The solution is to modify the initializer to match the client code version with the initializer version.</p>
<pre lang="actionscript3">public static const VERSION:String = "1.6";
public static function initialize(versionCheck:String = VERSION):void {
   if (versionCheck != VERSION) {
       throw new Error ("The version check failed! This library is version " + VERSION + ". Update your code or GTFO!");
   }
   // initialize library here
}</pre>
<p>And when you run the initializer, use the version number you&#8217;re expecting.</p>
<pre lang="actionscript3">MyLibrary.initialize("1.6");</pre>
<p>Some things to notice with this approach:</p>
<ul>
<li>I used a string instead of a number for the version number so that it would allow for sub-sub version numbers and other markers, e.g. &#8220;1.6.24 beta r545&#8243;</li>
<li>Because there is a default value for <code>versionCheck</code> in the initializer, providing a version number is optional. Using <code>MyLibrary.initialize()</code> will still work and throw no errors.</li>
<li>Unfortunately, there is not much you can do if the version numbers don&#8217;t match except to warn the client that the external code has changed. Still, I&#8217;ve found this to be very useful.</li>
</ul>
<p>The code for my initializer in its entirety after the jump&#8230;<br />
<span id="more-446"></span><br />
From <a href="http://code.google.com/p/kitchensynclib/source/browse/trunk/src/org/as3lib/kitchensync/KitchenSync.as">KitchenSync.as</a></p>
<pre lang="actionscript3">/**
* The current version of the library. Use this to verify that the library is the
* version that your software expects.
*/
public static const VERSION:String = "1.6";

/**
* Flag noting whether the engine has been initialized.
*/
private static var _initialized:Boolean = false;

/**
* Initializes the timing core for KitchenSync. Must be called before using any actions.
*
* @param frameRateSeed must be a DisplayObject that is added to the display list.
* @param versionCheck a string for the version you think you're using. e.g. 1.2 This is recommended
*                                         but not required. It will throw an error if you're using the wrong version of KS.
*/
public static function initialize(frameRateSeed:DisplayObject, versionCheck:String = VERSION):void
{       

	if (_initialized) {
		throw new IllegalOperationError("KitchenSync has already been initialized.");
	}
	if (versionCheck != VERSION) {
		throw new Error ("Version check failed. Please update to the correct version or to continue using this version (at your own risk) put the initialize() method inside a try{} block.");
	}

	// Initialization code omitted

	_initialized = true;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/version-checking/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Protip &#8211; Making an email forward look like it was sent for the first time</title>
		<link>http://dispatchevent.org/mims/protip-forwards/</link>
		<comments>http://dispatchevent.org/mims/protip-forwards/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 17:53:49 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[In Real Life]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=408</guid>
		<description><![CDATA[Has this ever happened to you?
You&#8217;re having an awesome birthday bash and you send out an email to all your closest friends&#8230; that is, all your closest friends except &#8216;Ed&#8217;. Now you&#8217;re faced with the embarrassing situation of having to invite your friend Ed post-invitum. But don&#8217;t fret, here&#8217;s a simple solution that will save [...]]]></description>
			<content:encoded><![CDATA[<p>Has this ever happened to you?</p>
<p>You&#8217;re having an awesome birthday bash and you send out an email to all your closest friends&#8230; that is, all your closest friends except &#8216;Ed&#8217;. Now you&#8217;re faced with the embarrassing situation of having to invite your friend Ed post-invitum. But don&#8217;t fret, here&#8217;s a simple solution that will save you loads of embarrassment!</p>
<p>Go from <a href="http://dispatchevent.org/wp-content/uploads/2008/09/before.jpg"><img class="size-thumbnail wp-image-410" title="before" src="http://dispatchevent.org/wp-content/uploads/2008/09/before-150x150.jpg" alt="Go from this..." width="150" height="150" /></a> to <a href="http://dispatchevent.org/wp-content/uploads/2008/09/after.jpg"><img class="size-thumbnail wp-image-409" title="after" src="http://dispatchevent.org/wp-content/uploads/2008/09/after-150x150.jpg" alt="...to this!" width="150" height="150" /></a></p>
<h3>Step 1. Find the original email</h3>
<p>Did you send a copy to yourself? Good! If not, check your sent folder. Not there? Ask your mom to forward the invite back to you.</p>
<h3>Step 2. Forward to yourself and BCC your friend.</h3>
<p>Click on the forward button. This time send it<strong> to yourself!</strong> In the BCC field put the name of the person (or people) you forgot. BCC stands for &#8220;blind carbon copy&#8221; and the names on this list won&#8217;t be listed so they&#8217;ll ony see your name listed.</p>
<h3>Step 3. Delete &#8220;fwd:&#8221; from the subject line.</h3>
<p>That&#8217;s a dead giveaway that you&#8217;re a loser and a fuck-up who doesn&#8217;t care about his friends.</p>
<h3>Step 4. Remove the quote formatting.</h3>
<p>You know the blue line that runs down the left side of the text that you&#8217;re forwarding? That&#8217;s the quote formatting. It may also appear as a &#8220;&gt;&#8221; or some other symbol. Taking that stuff out is the last step in making your email look fresh.</p>
<p>If you&#8217;re using Mac Mail, just highlight the quoted text and press Command + Option + &#8216; (apostrophe) until the blue line disappears.</p>
<p>Also make sure you remove the text that says &#8220;Begin forwarded message:&#8221;! Duh!</p>
<h3>Step 5. Make sure it looks right and send!</h3>
<p>If done properly, your email will look exactly like a brand new email and your friend will never know that you don&#8217;t really like them that much!</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/protip-forwards/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Tweening timeline animations with KitchenSync</title>
		<link>http://dispatchevent.org/mims/tweening-timeline-animations-with-kitchensync/</link>
		<comments>http://dispatchevent.org/mims/tweening-timeline-animations-with-kitchensync/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 23:31:33 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[Site-seeing]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Videogames]]></category>
		<category><![CDATA[physics & motion]]></category>
		<category><![CDATA[KitchenSync]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=284</guid>
		<description><![CDATA[One of the new features in KitchenSync 1.5 is the ability to tween animations on a MovieClip&#8217;s timeline&#8230; and I&#8217;m not just talking about gotoAndPlay(), I&#8217;m talking about controlling the starting and stopping points, speed, and easing functions of an animation on the timeline with code. It does this by incrementally controlling the current frame [...]]]></description>
			<content:encoded><![CDATA[<p>One of the new features in <a href="http://dispatchevent.org/mims/kitchensync-v1-5/">KitchenSync 1.5</a> is the ability to tween animations on a MovieClip&#8217;s timeline&#8230; and I&#8217;m not just talking about gotoAndPlay(), I&#8217;m talking about controlling the starting and stopping points, speed, and easing functions of an animation on the timeline with code. It does this by incrementally controlling the current frame number of the MovieClip using a <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/action/KSTween.html">KSTween</a> and a special <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/action/tweentarget/ITweenTarget.html">ITweenTarget</a> (a class used to control the values of an object) called <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/action/tweentarget/TimelineController.html"><strong>TimelineController</strong></a>.</p>
<p>Take this FLA animation.</p>
<p><a href="http://dispatchevent.org/wp-content/uploads/2008/07/timelineAnimationStill.png"><img src="http://dispatchevent.org/wp-content/uploads/2008/07/timelineAnimationStill.png" alt="MovieClip animation" /></a></p>
<p>As you can see, there is a simple animation using a guide layer and labels on the key frames.</p>
<p><span id="more-284"></span></p>
<p>The following SWF uses KitchenSync to control the same ball animation. As you can see, the duration and easing functions of the animation can be controlled. You can even animate backwards!</p>
<p><a href="/wp-content/uploads/2008/07/FlashIntegrationTest.swf">See it in action.</a></p>
<p>The source that controls this is here.</p>
<pre lang="actionscript3">package {
	import flash.display.MovieClip;

	import org.as3lib.kitchensync.KitchenSync;
	import org.as3lib.kitchensync.action.*;
	import org.as3lib.kitchensync.action.tweentarget.*;
	import org.as3lib.kitchensync.easing.Bounce;
	import org.as3lib.kitchensync.easing.Cubic;
	import org.as3lib.kitchensync.easing.Linear;
	import org.as3lib.kitchensync.easing.Oscillate;

	/**
	*	Demos the TimelineController which controls the animation of a MovieClip's timeline.
	*/
	public class FlashIntegrationTest extends MovieClip
	{
		protected var test1:MovieClip;

		public function FlashIntegrationTest()
		{
			super();
			// initialize kitchensync.
			KitchenSync.initialize(this, "1.5");

			// add a movieclip from the library
			test1 = MovieClip(new AnimationTest1());
			addChild(test1);

			// define the start and end frame with strings or ints or FrameLabel's
			var startLabel:* = "start";
			var endLabel:* = "end";

			// set up the TimelineController tween target.
			var tweenTarget:TimelineController = new TimelineController(test1, startLabel, endLabel);
			// Animate the ball with a linear ease.
			var tween:KSTween = KSTween.newWithTweenTarget(tweenTarget, "1s", 0, Linear.ease);

			// animate the ball backwards with a bounce tween
			var tween2:KSTween = tween.cloneReversed();
			tween2.duration = "4s";
			tween2.easingFunction = Bounce.easeOut;
			tween2.addTrigger(tween);

			// animate the ball with an oscillator
			var tween3:KSTween = KSTween.newWithTweenTarget(tweenTarget, "10m", "1s", Oscillate.sine);
			tween3.easingMod1 = 0.3;
			tween3.addTrigger(tween2);

			// start the animations
			tween.start();
		}

	}
}</pre>
<p>Pretty cool huh? We&#8217;re creating a new TimelineController and setting the boundaries of the animation then passing it to a new KSTween object. Each of the three tweens use different parameters and are triggered by the end of the one before it.</p>
<p>You can <a href="http://dispatchevent.org/wp-content/uploads/2008/07/timelineControllerDemo.zip">download the entire thing</a> and play around with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/tweening-timeline-animations-with-kitchensync/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Technique: Semaphores</title>
		<link>http://dispatchevent.org/roger/technique-semaphores/</link>
		<comments>http://dispatchevent.org/roger/technique-semaphores/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 09:51:37 +0000</pubDate>
		<dc:creator>Roger Braunstein</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.partlyhuman.com/blog/?p=160</guid>
		<description><![CDATA[For the past year(!) or so I&#8217;ve had a series of articles I meant to write about some intermediate programming concepts that can allow you to write code at a higher level. I regret that it&#8217;s taken so long to come around to them, but I hope they can be of some use. This series [...]]]></description>
			<content:encoded><![CDATA[<p>For the past year(!) or so I&#8217;ve had a series of articles I meant to write about some intermediate programming concepts that can allow you to write code at a higher level. I regret that it&#8217;s taken so long to come around to them, but I hope they can be of some use. This series will cover semaphores, asynchronous tokens, and green threads, and I may extend it with some brief notes on assertions and iterators. Today I&#8217;d like to talk about semaphores.</p>
<p><span id="more-160"></span></p>
<h3>Part The First, In Which There is Much Hemming and Hawing</h3>
<p>First, allow me a word of philosophical introduction. None of these concepts is very complicated, and even if you&#8217;re unfamiliar with the terminology, you are likely to have programmed something similar to them yourself. However, ingesting them conceptually and being able to use them in an encapsulated way makes code you write more high-level, and thus more powerful and more succinct, and to me, more beautiful. For any given programming language, some concepts are encoded in the language itself, but all other concepts must be built on top of the language. For example, the idea of objects is built into ActionScript 3.0 with keywords like <code>new</code> and <code>class</code>, but a concept like a loading queue is built using the language. For every language there is a line where this distinction is drawn, making for interesting languages like JavaScript where you are free to simulate Object Oriented programming in your own way with your own syntax by using closures. However, there is no Turing complete language &#8211; which is to say, no language you&#8217;re likely to use on a computer &#8211; for which there is a line defining things you simply cannot build. And the point here is that the distinction between things the language provides and things you build yourself is only the syntax, and how it runs. Furthermore, perhaps I am biased to say so, but I believe that OOP gives us fairly good syntax with which to define our own ways of doing things. What I&#8217;m coming to here, is that you can make a language smarter &#8211; and make it look natural doing it &#8211; and in this I take great joy.</p>
<p>So we come to my series of topics for some intermediate computer science topics. My articles have this in common: They cover features that could have been in the language, but since they aren&#8217;t, we can create our own versions which are no less, or only slightly less, useable and readable. By encapsulating these concepts in objects rather than solving them differently in different places, we are freed from again thinking of that specific problem, and code which relies on the concept becomes beautifully concise.</p>
<p>If you are a student of design patterns, you may well read this introduction and think that I will be writing a series of articles on patterns. However, I am reluctant to call these topics patterns. Perhaps this is because their use was understood far before patterns, or because I learned of them far before patterns. Or perhaps it has something to do with the fact that you can build these structures once and use them, so that they are more like utilities. However, if you want to call them patterns, go ahead. I think patterns serve the same purpose. They are ways to organize ideas in a higher level than the syntax of the language itself; and indeed some languages have no need for some patterns because the pattern is behind that invisible line of &#8220;things you can do inside the language.&#8221;</p>
<h3>So, You Mentioned Semaphores&#8230;</h3>
<p>At any rate, today&#8217;s topic is the humble semaphore. Semaphore is one of those glorious Computer Science words that makes me feel good about having spent 4 years at a prestigious university. Actually there are two categories of such words: inscrutable names for simple things, and inscrutable names for quite difficult things. Semaphore is one of the former. (NP-Complete is one of the latter.)</p>
<p>A semaphore in CS-speak is just a lock. Let&#8217;s not forget that semaphores are also signals made with flags in two arms to transmit information at a distance. It&#8217;s quite probable that the original meaning inspired the name for a lock, so let&#8217;s use it as an analogy.</p>
<p>These objects are quite old and venerable, because once our hardware and software was slow and not quite so parallel as it is now, and we used locks as a solution. Let&#8217;s say you have an old 15MB hard drive in your computer. Process A wants to write some data to the disk. Process B also wants to write some data to the disk. With nobody watching, they both go ahead and start writing merrily away. If you&#8217;re lucky, everything goes fine. If you&#8217;re not, they both end up writing to the same spot on the disk and one, or both, gets hosed. So venerable old operating systems put in a gatekeeper, and that&#8217;s your semaphore. Instead of saying</p>
<pre>disk.write();</pre>
<p>You now check with the gatekeeper.</p>
<pre>while (disk.isLocked())
{
	wait();
}
disk.lock();
disk.write();
disk.unlock();</pre>
<p>Okay, so in our imaginations let&#8217;s picture a little man with bronzed skin and zinc on his nose, sitting on his tall chair on the disk, and he signals by crossing his arms with two flags: &#8220;Sorry buddy, disk is closed for business right now. Some other fella is using it.&#8221; You check up later and he traces out the path of a circle, one hemisphere with each arm, from top to bottom: &#8220;Coast is clear, go ahead!&#8221; I guess semaphore kinda works as an analogy. But it&#8217;s really just easier to call it a lock.</p>
<p>No matter what you call it, a semaphore has only one purpose: prevent concurrent access.</p>
<h3>What Are They Good For?</h3>
<p>Thankfully we don&#8217;t have to lock down the entire disk when we&#8217;re writing data nowadays, though the physical limitations of the device really do prevent us from writing two bits of data to two locations at the same time. Operating systems are smarter than this now and will do all the queueing, and indeed often journaling, of disk writes for you.</p>
<p>However, we run into plenty of other situations where we still lock things down unequivocally while in use. For instance, some tools will lock a database from being accessed while writing to it.</p>
<p>You might want to use a semaphore for&#8230;</p>
<ol>
<li>preventing actions which interfere with a process in motion</li>
<li>objects that can&#8217;t be used by two simultaneous clients</li>
<li>processes that take multiple steps over a period of time</li>
</ol>
<p>And here&#8217;s the thing&#8230; they&#8217;re pretty useful in websites too. I usually want to prevent any kind of navigations when a transition is in progress, or when the next section is loading. You want to prevent input into a form while a form is submitting. Because web programming is so event-driven, asynchronous, and animation-heavy, it often makes sense to lock actions or objects for a short period of time.</p>
<h3>Does It Really Need Its Own Class?</h3>
<p>But wouldn&#8217;t a simple &#8220;locked&#8221; member variable do the trick, you might ask? Well, you can do it that way, but you can also add some useful features to the basic implementation of a semaphore and suddenly it becomes a lot more powerful. For instance, you could allow multiple reservations. You could track who has a reservation on the shared resource. You could broadcast an event when an object becomes available or unavailable. Here I will present two implementations of a semaphore. First, the abstract base class, so that we can use either implementation at our will.</p>
<h3>Abstract Semaphore</h3>
<pre>package com.partlyhuman.semaphore
{
	import flash.events.EventDispatcher;

	[Event(type="com.partlyhuman.semaphore.SemaphoreEvent", name="available")]
	[Event(type="com.partlyhuman.semaphore.SemaphoreEvent", name="unavailable")]
	public class Semaphore extends EventDispatcher
	{
		protected var _description:String;
		public function get description():String {return _description;}

		protected var _owner:Object;
		public function get owner():Object {return _owner;}

		public function Semaphore(owner:Object = null, description:String = null)
		{
			_owner = owner;
			_description = description;
			initialize();
		}

		protected function initialize():void
		{
			throw new Error("Abstract Method");
		}

		public function get locks():int
		{
			throw new Error("Abstract Method");
			return 0;
		}

		public function get isLocked():Boolean
		{
			throw new Error("Abstract Method");
			return false;
		}

		override public function toString():String
		{
			return "[Semaphore " + description + "]";
		}
	}
}</pre>
<p>And the semaphore events,</p>
<pre>package com.partlyhuman.semaphore
{
	import flash.events.Event;

	public class SemaphoreEvent extends Event
	{
		public static const AVAILABLE:String = "semaphoreAvailable";
		public static const UNAVAILABLE:String = "semaphoreUnavailable";

		public function SemaphoreEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
		{
			super(type, bubbles, cancelable);
		}

	}
}</pre>
<h3>A Basic Implementation</h3>
<p>This implementation merely uses a counter. Straightforward, but once you start using semaphore objects to lock your navigation or your input fields, you will start to see how this simple object can untangle your state logic.</p>
<pre>package com.partlyhuman.semaphore
{
	public class SimpleSemaphore extends Semaphore
	{
		protected var _locks:int = 0;

		public function SimpleSemaphore(owner:Object = null, description:String = null)
		{
			super(owner, description);
		}

		override protected function initialize():void
		{
			_locks = 0;
		}

		override public function get locks():int
		{
			return _locks;
		}

		override public function get isLocked():Boolean
		{
			return (_locks > 0);
		}

		public function lock():void
		{
			if (_locks++ == 0)
			{
				dispatchEvent(new SemaphoreEvent(SemaphoreEvent.UNAVAILABLE));
			}
		}

		public function unlock():void
		{
			_locks--;
			if (locks < 0)
			{
				throw new Error("Semaphore Asymmetrically Unlocked!");
				locks = 0;
			} else if (locks == 0) {
				dispatchEvent(new SemaphoreEvent(SemaphoreEvent.AVAILABLE));
			}
		}
	}
}</pre>
<h3>An Alternative Implementation</h3>
<p>In this implementation, you get a receipt for your reservation. If you happen to need to hold on to a shared resource through a multi-step process that involves many objects, you might end up with a lot of dependencies. This implementation solves the problem by allowing you to pass around a lock object. Any code with a reference to the lock can release it, without requiring a dependency on the source of the lock itself.</p>
<pre>package com.partlyhuman.semaphore
{
	public class Lock
	{
		protected var owner:TokenSemaphore;

		public function Lock(owner:TokenSemaphore)
		{
			this.owner = owner;
		}

		public function release():void
		{
			owner.releaseLock(this);
		}
	}
}</pre>
<pre>package com.partlyhuman.semaphore
{
	public class TokenSemaphore extends Semaphore
	{
		protected var tokenPool:Array;

		public function TokenSemaphore(owner:Object = null, description:String = null)
		{
			super(owner, description);
		}

		override protected function initialize():void
		{
			tokenPool = new Array();
		}

		override public function get locks():int
		{
			return tokenPool.length;
		}

		override public function get isLocked():Boolean
		{
			return (tokenPool.length > 0);
		}

		public function getLock():Lock
		{
			if (locks == 0)
			{
				dispatchEvent(new SemaphoreEvent(SemaphoreEvent.UNAVAILABLE));
			}

			var lock:Lock = new Lock(this);
			tokenPool.push(lock);
			return lock;
		}

		internal function releaseLock(lock:Lock):void
		{
			var index:int = tokenPool.indexOf(lock);
			if (index == -1)
			{
				throw new Error("TokenSemaphore: a lock was released that could not be found");
				return;
			}

			tokenPool.splice(index, 1);
			lock = null;

			if (!isLocked) dispatchEvent(new SemaphoreEvent(SemaphoreEvent.AVAILABLE));
		}

	}
}</pre>
<h3>Conclusion</h3>
<p>Using semaphores in your code is a great way to avoid complicated state logic. You can move the logic of tracking usage to the semaphore object, and handle the results of locking or unlocking only when it has an effect. Though a simple concept, using it as a tool in your toolkit can make your code beautiful and concise. And you can design additional functionality into your own implementation. For example, I will soon explain a semaphore which binds to an asynchronous token... or you could write a semaphore which actually queued up requests.</p>
<p>Let me know what you think, and see you soon with the next installment!</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/roger/technique-semaphores/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Introduction to Flex Resource Bundles</title>
		<link>http://dispatchevent.org/roger/introduction-to-flex-resource-bundles/</link>
		<comments>http://dispatchevent.org/roger/introduction-to-flex-resource-bundles/#comments</comments>
		<pubDate>Fri, 09 May 2008 06:31:08 +0000</pubDate>
		<dc:creator>Roger Braunstein</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.partlyhuman.com/blog/roger/introduction-to-flex-resource-bundles</guid>
		<description><![CDATA[Hark, Flex developers. Lend me your ears! I must take this post to implore you: use Resource Bundles! Trust me, I know, there&#8217;s a lot to keep up with these days, but if you aren&#8217;t already privy to the awesome secrets of the humble bundle, hopefully I can help convince you to use them. I&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>Hark, Flex developers. Lend me your ears! I must take this post to implore you: use Resource Bundles! Trust me, I know, there&#8217;s a lot to keep up with these days, but if you aren&#8217;t already privy to the awesome secrets of the humble bundle, hopefully I can help convince you to use them. I&#8217;ll show you how, without breaking one bead of sweat from your brow! First, let me tell you why they&#8217;re cool. Then, I&#8217;ll show you how to get rolling with your first bundle. Then, I&#8217;ll set you loose, and hopefully you can all write in with excellent questions and help me make this a great resource for the next readers! Read on, fair Flexer.<br />
<span id="more-251"></span></p>
<h3>Why Bundles Will Give You a New Brain</h3>
<p><a href="http://www.comedycentral.com/videos/index.jhtml?videoId=60667&#038;title=power-marketing"><img src="http://partlyhuman.com/articles/resource-bundles/new-brain.jpg" style="float: right; margin-left: 1em" alt="This is from Upright Citizens Brigade. I don't advocate getting really high every day or doing your dishes in the bathtub."/></a></p>
<p>Eight years ago, I weighed 500lbs. I was getting really high every day. And I was washing my dishes in the bathtub.  But thanks to resource bundles, I own a mansion, I&#8217;ve got a summer home in Maine, I got an awesome boat, I got a jet pack, and I got a sweet lookin&#8217; wife.</p>
<p>What&#8217;s a resource bundle? It&#8217;s a <em>set of values</em> that you <em>externalize</em> from your source code in a <em>properties file</em>. And it can be swapped out at compile time or, with Flex 3, at runtime. Think of it like a style sheet for values. Most of the time, these values are text. But without too much hassle, you can use resource bundles to parameterize all types of data.</p>
<p>Resource bundles are probably most useful, and most commonly used for, <em>localization</em>. Localization (pardon the didacticism) is the process of making software comprehensible for multiple regions with different languages or ways of writing. Sometimes you&#8217;ll see this term written L10n. For example, in porting your &#8220;Hello, world&#8221; application for a Japanese audience, you&#8217;d probably make it say something like &#8220;今日は、世界&#8221; instead. Resource bundles are <em>perfect</em> for supporting multiple locales.</p>
<p>This obvious use case, I&#8217;m afraid, might have prevented many of you from looking into resource bundles. If resource bundles are for localization, and you&#8217;re building a site that doesn&#8217;t need to be localized, you might well overlook their benefits, as I did for some time. However, here&#8217;s some of the benefits of using resource bundles &#8212; even if it&#8217;s <em>just one single bundle</em>.</p>
<p>Using resource bundles, you can give every application you write a copy deck. If you&#8217;ve worked with almost any client ever, I&#8217;m sure you&#8217;ve had to make a copy change. Who wants to go digging through source code to find that string? Put all your application&#8217;s copy in a resource bundle, and you can not only make these changes with ease, you can deliver source code that anyone can modify easily. (Copy decks are a necessity when using translation services as well.)</p>
<p>You can use resource bundles to store configuration values such as paths, numbers, Boolean flags, debug mode, overrides, etc. You can use a resource bundle instead of a configuration file or static constants.</p>
<p>You can even use resource bundles to reskin applications. Flex lets you <em>parameterize embedded images</em> in resource bundles. Alternately, if you load images at runtime, you can parameterize those URLs in a resource bundle. So, if your code references resources instead of direct embeds, you can change the look of your app by swapping out the bundle with all the image embeds!</p>
<p>Even if you don&#8217;t use resource bundles for any sort of behavior, language, or appearance toggling in your application, bundles are a fantastic way to <em>separate code and content</em> and <em>organize related sets of content</em>.</p>
<p>In brief, resource bundles will make your life easier, your program modular, and your project structure tidy!</p>
<h3>What a World With Resource Bundles Looks Like</h3>
<p>Pretty soon I&#8217;ll show you the specifics of how to set up your project to use resource bundles. But before we get into technicalities, let me describe a few formats. There&#8217;s a few ways you can use resources, and there&#8217;s the property file format to cover as well.</p>
<p>Ok, again pardon the ultimately pedantic example, but let&#8217;s say you have a hello world app.</p>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
	&lt;mx:Label text=&quot;Hello, world!&quot;/&gt;
&lt;/mx:Application&gt;</pre>
<p>You clearly wrote this application for an English-speaking audience. And that bias exists in your code. It&#8217;s completely tied to your source file! Shame. If you wanted to write a Spanish version, you&#8217;d have to go right in and edit your source code:</p>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
	&lt;mx:Label text=&quot;¡Hola, mundo!&quot;/&gt;
&lt;/mx:Application&gt;</pre>
<p>But, with resource bundles, this is what the one, true, final and never-changing source code could look like:</p>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
	&lt;mx:Label text=&quot;<u>@Resource(key='message', bundle='copydeck')</u>&quot;/&gt;
&lt;/mx:Application&gt;
</pre>
<p>That&#8217;s one way, and indeed my favored way, of accessing resources from a resource bundle. This is going to look for the key <code>message</code> inside the bundle called <code>copydeck.properties</code>, and place its value in the <code>text</code> attribute of this Label instance, thus setting the text. Right now it looks like a lot <em>more</em> to type, but trust me, once you have a site or app with hundreds of lines of text, you are really going to appreciate how this makes your code concise and puts the text all together where it should be!</p>
<p>Note that you can use this <code>@Resource</code> directive in MXML in more places than just text attributes. You could use it to set tooltips, style properties, sizes, all kinds of things!</p>
<p>So let&#8217;s take a quick look at this outrageously simple properties file. This file format is really really easy.</p>
<pre>#locale/en_US/copydeck.properties
message=Hello, world!
message-size=30</pre>
<pre>#locale/es_MX/copydeck.properties
message=¡Hola, mundo!
message-size=40</pre>
<p>Here we see two copies of the properties file, made for two locales (American English and Mexican Spanish &#8212; locales are not just specific to the language but the region as well, but that&#8217;s another story). There&#8217;s pretty much only three things to know about properties files. </p>
<ul>
<li>Key <code>=</code> value. Do I need to explain this? Don&#8217;t sweat the whitespace.</li>
<li>Comments are whole lines that begin with <code>#</code>.</li>
<li>Properties are one line long unless you end the line with a backtick (<code>\</code>), in which case you can continue on the next line.</li>
</ul>
<p>In reality, there are alternate formats for the first two rules, but only use that if you <em>really have to be different</em>. There&#8217;s something to be said for the naming convention of the bundles. The directory structure I&#8217;ll explain a bit later, but know that en_US and es_MX are locale codes, combining a language code and a country code. The name of the file before its .properties extension is going to yield the bundle name itself.</p>
<p>Now, you can skip the whole step of specifying the bundle name by having one properties file per class file, and naming the properties file in parallel with the name of the class using it. If you do this, you can omit the <code>bundle='whatever'</code> attribute of the <code>@Resource</code> directive, but I advise against this. I advocate that you split up your resource bundles by purpose. For example, one recent project I worked on uses a bundle for copy and a bundle for skinning. Another recent project uses one bundle for copy and another for stylesheets.</p>
<p>So I hear you, you&#8217;re one of those hardcore doods who uses Flex but prefers to code in AS3. That&#8217;s cool, I&#8217;m down with that. Or maybe you just have something more interesting to do with those values coming out of resource bundles (configuration variables perhaps). There&#8217;s some nice ways of accessing values from resource bundles in code. Maybe looking at this will get you started:</p>
<pre>package
{
	import mx.containers.Canvas;
	import mx.controls.Label;

	<u>[ResourceBundle(&quot;copydeck&quot;)]</u>
	public class View extends Canvas
	{
		public function View()
		{
			super();
			var label:Label = new Label();
			label.text = <u>resourceManager.getString(&quot;copydeck&quot;, &quot;message&quot;)</u>;
			label.setStyle(&quot;fontSize&quot;, <u>resourceManager.getNumber(&quot;copydeck&quot;, &quot;message-size&quot;)</u>);
			addChild(label);
		}
	}
}</pre>
<p>If you&#8217;re in a class that doesn&#8217;t have its own reference to the ResourceManager, like Canvas here does, you can equally well use <code>ResourceManager.getInstance()</code>. Further, there are <a href="http://livedocs.adobe.com/flex/3/langref/index.html?mx/resources/IResourceManager.html&#038;mx/resources/class-list.html">lots of other cool typed accessor methods</a> you can use. Keep in mind that any bundles you reference in AS3 only must be explicitly included by using <code>[ResourceBundle]</code> metadata tags.</p>
<p>For more information about intermediate techniques like embedding assets and loading/swapping resource bundles at runtime, check out the very good <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=l10n_1.html">section on localization in the Livedocs</a>.</p>
<h3>The Petty Particulars of Putting it to Practice</h3>
<p>Now, I&#8217;m not going to leave you hanging with just some code examples. There&#8217;s a few things you need to know about structuring your Flex projects to take advantage of resource bundles. It&#8217;s really not that complicated, though, so not to worry!</p>
<p>First, you should pick a place for your resource bundles to live. Even if I&#8217;m only ever making apps for my United States English locale, I still like to make a <code>locale/en_US</code> folder, and place all my properties files inside there. I recommend you do the same.</p>
<p>Now here&#8217;s one tricky point. This directory must be one of the source directories in your Flex project. The compiler has to be able to crawl to those properties files, and it stays away from any place you haven&#8217;t specified in your build path. Again, even if I only have one locale ever, I like to keep this parameterized. Assuming you used the directory structure above, step one is to add the following directory to your build path:</p>
<pre>locale/{locale}</pre>
<p>The play-by-play, if you need it: right-click your project, choose Properties. Choose ActionScript Build Path on the left column, choose the Source Path tab, click Add Folder&#8230; and enter <code>locale/{locale}</code>.</p>
<p><img src="http://partlyhuman.com/articles/resource-bundles/build-path.gif" alt="screenshot"/><br clear="all"/></p>
<p>Finally, Flex Builder is going to get this locale variable from somewhere, and that&#8217;s from the arguments sent to mxmlc. Simply add the option</p>
<pre>-locale=en_US</pre>
<p>to your compiler arguments, or of course, substitute the locale in use. This value will replace the <code>{locale}</code> variable in the source path, and switch mxmlc to use the copies of the properties files in the correct location for the locale (or skin, or whatever&#8230;).</p>
<p>Again, the play-by-play. Right click your project, choose Properties. Choose ActionScript Compiler on the left column, and add the option just mentioned to any others that your project requires (if any).</p>
<p><img src="http://partlyhuman.com/articles/resource-bundles/compiler-arguments.gif" alt="screenshot"/></p>
<h3>Conclusion</h3>
<p>That&#8217;s all it should take to get you started with resource bundles! I hope that I&#8217;ve convinced you that resource bundles are a fun, safe, and effective way to separate your code and your content, whether your application will be localized and skinned or not! Separate your copy from your code. The next person to touch your code will thank you. If you use MXML with external CSS files <em>and</em> external resource bundles, you might achieve some sort of ultimate code separation enlightenment.</p>
<p>Did I miss anything? Run into any problems? Leave me a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/roger/introduction-to-flex-resource-bundles/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>KitchenSync News: Patch released v1.0.1, source files for Flash CS3, more docs</title>
		<link>http://dispatchevent.org/mims/kitchensync-news-patch-released-v101-source-files-for-flash-cs3-more-docs/</link>
		<comments>http://dispatchevent.org/mims/kitchensync-news-patch-released-v101-source-files-for-flash-cs3-more-docs/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 21:30:05 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://mimswright.com/blog/?p=239</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/kitchensynclib/"><img src="http://farm3.static.flickr.com/2141/2227980615_054e2f3c8a.jpg" alt="kitchenSync"</a></p>
<p>Hey KS Fans,</p>
<p><a href="http://code.google.com/p/kitchensynclib/">KitchenSync</a> version 1.0.1 was released last week. This version is just a patch that fixes a few minor issues. Here&#8217;s the change log for this version.</p>
<pre>
<code>
===== v1.0.1 (2008.02.04) ======
Fixed Cubic.easeOut bug.
Made getters for Tween's toValue and fromValue.
Added source code to main download.
Added metadata for events.
Updated docs and added summaries to all wiki pages.
</code>
</pre>
<p>I received some feedback from people who were having trouble setting up KitchenSync for use with Flash CS3. I didn&#8217;t know this before but you cannot use .swc files compiled with the Flex SDK in a .fla file (WTF, Adobe!) Also, some people were confused by having to use SVN to get the source. To help solve these problems, I&#8217;ve added <a href="http://code.google.com/p/kitchensynclib/downloads/detail?name=KitchenSyncLib.1.0.1.source.zip&#038;can=2&#038;q=#makechanges">the latest source code</a> as its own download.</p>
<p>I&#8217;ve also written EVEN MORE <a href="http://code.google.com/p/kitchensynclib/w/list">documentation</a> including <a href="http://code.google.com/p/kitchensynclib/wiki/Installation">help for downloading and setting up</a> the source code.</p>
<p>Finally, if you&#8217;re using KS, drop me a line or post to <a href="http://groups.google.com/group/kitchensynclib">the mailing list</a>. I&#8217;d love to hear any feedback you may have!</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/kitchensync-news-patch-released-v101-source-files-for-flash-cs3-more-docs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The State pattern in Flex &#8211; combining view states with logical states</title>
		<link>http://dispatchevent.org/mims/the-state-pattern-in-flex-combining-view-states-with-logical-states/</link>
		<comments>http://dispatchevent.org/mims/the-state-pattern-in-flex-combining-view-states-with-logical-states/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 07:15:17 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[User Experience]]></category>

		<guid isPermaLink="false">http://mimswright.com/blog/?p=229</guid>
		<description><![CDATA[If you&#8217;ve used Flex, you&#8217;ve no doubt (er, hopefully) been using View States (AKA &#60;mx:State&#62;) to change the look of your RIA as it progresses through different situations of use. While  this is immeasurably useful, it does not necessarily qualify as an implementation of the State Design Pattern which allows you to change not [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve used Flex, you&#8217;ve no doubt (er, hopefully) been using <a href="http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00000923.html#321190">View States</a> (AKA &lt;mx:State&gt;) to change the look of your RIA as it progresses through different situations of use. While  this is immeasurably useful, it does not necessarily qualify as an implementation of the <a href="http://www.google.com/url?sa=t&#038;ct=res&#038;cd=5&#038;url=http%3A%2F%2Fwww.cs.umd.edu%2Fclass%2Ffall2002%2Fcmsc433-0101%2FLectures%2FdesignPatterns2.pdf&#038;ei=xtWWR6W9Ao-siAHp6_zbCQ&#038;usg=AFQjCNET3tf19Z44Ejoy9f-ilwgu_3ahrg&#038;sig2=XkAAY1IAvln2Hmpt-plpGQ">State Design Pattern</a> which allows you to change not only how a component looks but how it <em>functions</em> as well.<br />
(for more on design patterns, read my favorite book <a href="http://www.amazon.com/Head-First-Design-Patterns/dp/0596007124/tag=dis03-20">Head first design patterns</a>).<br />
<span id="more-229"></span><br />
Take the following example for a &#8220;Breakfast maker&#8221; application. </p>
<p><a href='http://mimswright.com/blog/wp-content/uploads/2008/01/logicalstatedemo.zip' title='LogicalStateDemo'>Download Source!</a></p>
<p><code><strong>StateDemo.mxml</strong></code></p>
<pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;absolute&quot; xmlns:local=&quot;*&quot; currentState=&quot;{ENGLISH}&quot;&gt;
	&lt;mx:Script&gt;
		&lt;![CDATA[
			// define the state names as constants
			static public const ENGLISH:String = &quot;English&quot;;
			static public const FRENCH:String = &quot;French&quot;;

			/**
			 * When the &quot;make breakfast&quot; button is clicked, display the steps
			 * you'll need to follow to make breakfast.
			 * Imagine that you'd need to implement all of these steps as functions
			 * and that there are several more languages to support.
			 */
			protected function onBreakfastButton(event:Event):void {
				if (currentState == ENGLISH) {
					output.text = &quot;Fry eggs&quot; +
								  &quot;\nFry tomatoes&quot; +
								  &quot;\nToast bread&quot; +
								  &quot;\nMake tea&quot;;
				}
				if (currentState == FRENCH) {
					output.text = &quot;Tartiner du beurre sur baguette&quot; +
								  &quot;\nMettre le yaourt dans un bol&quot; +
								  &quot;\nTranche les fruits&quot; +
								  &quot;\nFaire cafe&quot;;
				}

			}
		]]&gt;
	&lt;/mx:Script&gt;

	&lt;!-- Define the changes to the view in the &lt;mx:states&gt; tags --&gt;
	&lt;mx:states&gt;
		&lt;mx:State name=&quot;{ENGLISH}&quot;&gt;
			&lt;mx:SetProperty target=&quot;{breakfastButton}&quot; name=&quot;label&quot; value=&quot;Make Breakfast&quot; /&gt;
		&lt;/mx:State&gt;
		&lt;mx:State name=&quot;{FRENCH}&quot;&gt;
			&lt;mx:SetProperty target=&quot;{breakfastButton}&quot; name=&quot;label&quot; value=&quot;	Pr&Atilde;&copy;parer des petits-d&Atilde;&copy;jeuners&quot; /&gt;
		&lt;/mx:State&gt;
	&lt;/mx:states&gt;

	&lt;mx:VBox&gt;
		&lt;mx:Button id=&quot;breakfastButton&quot; click=&quot;onBreakfastButton(event)&quot; /&gt;
		&lt;mx:TextArea id=&quot;output&quot;  height=&quot;100&quot; width=&quot;250&quot;/&gt;
		&lt;mx:HBox&gt;
			&lt;!-- Swap states using these buttons --&gt;
			&lt;mx:Button label=&quot;English&quot; click=&quot;{currentState = ENGLISH}&quot; /&gt;
			&lt;mx:Button label=&quot;French&quot; click=&quot;{currentState = FRENCH}&quot; /&gt;
		&lt;/mx:HBox&gt;
	&lt;/mx:VBox&gt;
&lt;/mx:Application&gt;
</pre>
<p>Compiling this code gives you the following&#8230;<br />
<a href="/wp-content/uploads/2008/01/statedemo.swf">View SWF</a></p>
<h2>The problem</h2>
<p>While there&#8217;s nothing inherently wrong with this application, there could be complications when trying to make changes to the logic. First of all, the <code>onButtonClick()</code> handler has to provide different functionality based on the <code>currentState</code>. The states themselves need to add labels to the <code>breakfastButton</code>. Imagine what would happen if you expanded this application to support 15 languages or to create lunch, dinner, and teatime. Things could get out of control fast!</p>
<h2>The Solution &#8211; applying the state design pattern</h2>
<p>The state design pattern allows you to separate out state specific functionality and defer the execution of methods to those state objects. </p>
<p><img src='http://mimswright.com/blog/wp-content/uploads/2008/01/picture-2.png' alt='BasicStatePatternDiagram' /></p>
<p>I&#8217;ll combine the state pattern with the view states by making a <code>currentLogicalState</code> property of the application. This setter will also automatically set the <code>currentState</code> based on a name stored in the <code>currentLogicalState</code>. This is easier done than said&#8230;</p>
<h3>1. Define a logical state interface</h3>
<p>My logical state interface only needs to have one getter for <code>name</code> so that we can associate it with a view state.<br />
<strong><br />
<code><strong>ILogicalState.as</strong></code></p>
<pre>
package
{
	public interface ILogicalState
	{
		function get name():String;
	}
}
</pre>
<h3>2. create a customized state interface for this application</h3>
<p>This interface should contain any methods that are state dependent. </p>
<p><code><strong>IBreakfastMakerState.as</strong></code></p>
<pre>
package
{
	public interface IBreakfastMakerState extends ILogicalState
	{
		function get breakfastInstructions():String;
		function get breakfastLabel():String;
	}
}
</pre>
<p>Note that this interface extends ILogicalState.</p>
<h3>3. create state classes</h3>
<p>I&#8217;ll create two different state classes, one for English breakfast and one for French Breakfast. Each will implement the <code>IBreakfastMakerState</code> interface and will provide the functionality needed to prepare the appropriate breakfast.</p>
<p><code><strong>EnglishBreakfastState.as</strong></code></p>
<pre>
package
{
	public class EnglishBreakfastState implements IBreakfastMakerState
	{
		public function get name():String
		{
			return "English";
		}

		public function get breakfastInstructions():String
		{
			return "Fry eggs" +
				   "\nToast bread" +
				   "\nFry tomatoes" +
				   "\nMake tea";
		}
		public function get breakfastLabel():String {
			return "Make Breakfast";
		}
	}
}
</pre>
<p><code><strong>FrenchBreakfastState.as</strong></code></p>
<pre>
package
{
	public class FrenchBreakfastState implements IBreakfastMakerState
	{
		public function get name():String
		{
			return "French";
		}

		public function get breakfastInstructions():String
		{
			return "Tartiner du beurre sur baguette" +
				   "\nMettre le yaourt dans un bol" +
				   "\nTranche les fruits" +
				   "\nFaire cafe";
		}

		public function get breakfastLabel():String {
			return "Préparer des petits-déjeuners";
		}
	}
}
</pre>
<h3>4. Refactor StateDemo.mxml</h3>
<p>Finally, rewrite the StateDemo.mxml to take advantage of the new state objects and call it LogicalStateDemo.mxml. (Note, this application should run exactly the same as StateDemo.mxml)</p>
<p><code><strong>LogicalStateDemo.mxml</strong></code></p>
<pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;absolute&quot; xmlns:local=&quot;*&quot;
	initialize=&quot;onInitialize(event)&quot;&gt;
	&lt;mx:Script&gt;
		&lt;![CDATA[

			// define the logical states as constants
			static public const ENGLISH:IBreakfastMakerState = new EnglishBreakfastState();
			static public const FRENCH:IBreakfastMakerState = new FrenchBreakfastState();

			/**
			 * keep track of the current logical state and when the currentLogicalState changes
			 * update the currentState using its name property.
			 */
			protected var _currentLogicalState:IBreakfastMakerState;
			public function set currentLogicalState(state:IBreakfastMakerState):void {
				_currentLogicalState = state;
				currentState = _currentLogicalState.name;
			}

			protected function onInitialize(event:Event):void {
				currentLogicalState = ENGLISH;
			}

			protected function onBreakfastButton(event:Event):void {
				// rely on the logical state to handle the logic of preparing the breakfast.
				output.text = _currentLogicalState.breakfastInstructions;
			}
		]]&gt;
	&lt;/mx:Script&gt;

	&lt;!-- Define the changes to the view in the &lt;mx:states&gt; tags --&gt;
	&lt;mx:states&gt;
		&lt;!-- Name each view state using the name of the logical state --&gt;
		&lt;mx:State name=&quot;{ENGLISH.name}&quot;&gt;
			&lt;!-- Change the label using a value from the logical state --&gt;
			&lt;mx:SetProperty target=&quot;{breakfastButton}&quot; name=&quot;label&quot; value=&quot;{ENGLISH.breakfastLabel}&quot; /&gt;
		&lt;/mx:State&gt;
		&lt;mx:State name=&quot;{FRENCH.name}&quot;&gt;
			&lt;mx:SetProperty target=&quot;{breakfastButton}&quot; name=&quot;label&quot; value=&quot;{FRENCH.breakfastLabel}&quot; /&gt;
		&lt;/mx:State&gt;
	&lt;/mx:states&gt;

	&lt;mx:VBox&gt;
		&lt;mx:Button id=&quot;breakfastButton&quot; click=&quot;onBreakfastButton(event)&quot; /&gt;
		&lt;mx:TextArea id=&quot;output&quot;  height=&quot;100&quot; width=&quot;250&quot;/&gt;
		&lt;mx:HBox&gt;
			&lt;!-- Swap logical states using these buttons --&gt;
			&lt;mx:Button label=&quot;English&quot; click=&quot;{currentLogicalState = ENGLISH}&quot; /&gt;
			&lt;mx:Button label=&quot;French&quot; click=&quot;{currentLogicalState = FRENCH}&quot; /&gt;
		&lt;/mx:HBox&gt;
	&lt;/mx:VBox&gt;
&lt;/mx:Application&gt;
</pre>
<p><em>Et voila!</em> A state pattern that works with the existing view states. This may seem like a lot of work for such a simple thing but it will really pay off in the long run on a complicated RIA.</p>
<p><a href='http://mimswright.com/blog/wp-content/uploads/2008/01/logicalstatedemo.zip' title='LogicalStateDemo'>Download Source!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/the-state-pattern-in-flex-combining-view-states-with-logical-states/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>No children on the stage &#8211; a confusing Flash CS3 display list issue</title>
		<link>http://dispatchevent.org/mims/no-children-on-the-stage-a-confusing-flash-cs3-display-list-issue/</link>
		<comments>http://dispatchevent.org/mims/no-children-on-the-stage-a-confusing-flash-cs3-display-list-issue/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 01:00:02 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[AS3 Bible]]></category>

		<guid isPermaLink="false">http://mimswright.com/blog/?p=227</guid>
		<description><![CDATA[A reader wrote to me with an interesting Flash CS3 problem that had me stumped at first (mostly because I use FlexBuilder instead of Flash). I thought I&#8217;d post the answer here so we can all benefit from it.
The Problem
Ben H. writes&#8230;

I’ve been trying to get familiar with a “best practice” on [looping through the [...]]]></description>
			<content:encoded><![CDATA[<p>A reader wrote to me with an interesting Flash CS3 problem that had me stumped at first (mostly because I use FlexBuilder instead of Flash). I thought I&#8217;d post the answer here so we can all benefit from it.</p>
<h3>The Problem</h3>
<p>Ben H. writes&#8230;</p>
<blockquote><p>
I’ve been trying to get familiar with a “best practice” on [looping through the display list].  The trouble is, when I enter the following on the first frame of a blank .fla file:</p>
<p><code>trace("Number of Children in a blank SWF:"+stage.numChildren);<br />
trace("Child 1:" + stage.getChildAt(0));</code></p>
<p>I get this:</p>
<p><code>Number of Children in a blank SWF:1<br />
Child 1:[object MainTimeline]</code></p>
<p>Now that may seem grand, but I’ve drawn several shapes and have a text field and named movieclip instances on stage as well – so why [does it only count one child?]
</p></blockquote>
<p>Solution after the jump.<br />
<span id="more-227"></span></p>
<h3>The Solution</h3>
<p>The first thing I noticed here is that the trace statement seems to be tracing out an instance of the MainTimeline class. I tried seeing if the objects appear inside of the MainTimeline with this code (notice i had to cast the timeline to a DisplayObjectContainer to check its children):<br />
[ftf]<br />
import flash.display.*;<br />
var timeline:DisplayObjectContainer = DisplayObjectContainer(stage.getChildAt(0));<br />
trace(&#8220;Number of Children in a blank SWF:&#8221; + timeline.numChildren);<br />
trace(&#8220;Child 1:&#8221; + timeline.getChildAt(0));<br />
[/ftf]<br />
Which displayed:<br />
<code><br />
Number of Children in a blank SWF:3<br />
Child 1:[object Shape]<br />
</code><br />
OK. So the shapes are there, it&#8217;s just that they are inside the MainTimeline&#8217;s display list instead of in the Stage&#8217;s. Since I&#8217;m a little rusty on the Flash authoring tool, it took me a minute to realize that the MainTimeline is the class that Flash automatically creates when a Document Class is not specified by the developer. (By the way, I just want to say that I officially do not condone putting actions on frames when you&#8217;re using AS3. I really think you should always use a Document Class (which is a way to specify a class to use as your main timeline (I know, nested parentheses!)). You can use any class as long as it extends Sprite or MovieClip.  In case you&#8217;re not familiar with this, Roger made a <a href="http://partlyhuman.com/articles/screencasts/running-as3-examples-using-flash.html">nifty screencast</a> that shows how to set up your .FLA to use classes.) I was reminded that when you do define a Document Class such as this one:<br />
[ftf]<br />
package {<br />
	import flash.display.*;<br />
	public class Demo extends Sprite {<br />
		public function Demo() {<br />
			trace(&#8220;Number of Children in this SWF:&#8221; + numChildren);<br />
			trace(&#8220;Child 1:&#8221; + getChildAt(0));<br />
		}<br />
	}<br />
}<br />
[/ftf]<br />
You simply access the children with <code>getChildren()</code> or <code>this.getChildren()</code> instead of referencing the Stage or the MainTimeline (because this <em>is</em> the main timeline). Try this on the first frame of the FLA (no don&#8217;t!) and you&#8217;ll get the same result.<br />
So what&#8217;s the difference between the Stage and the Document Class? The Stage is a special type of Display Object that is &#8216;owned and operated&#8217; by the Flash Player. It also contains some special properties, such as  <code>frameRate</code>, which affect all the other display lists. The Document Class, on the other hand, is defined by the developer and can be customized to fit your needs.<br />
Good question Ben. It really is confusing that you&#8217;re drawing objects on the &#8217;stage&#8217; but calling <code>stage.getChildren()</code> doesn&#8217;t return those objects.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/no-children-on-the-stage-a-confusing-flash-cs3-display-list-issue/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pimp my &#8216;clipse &#8211; a list of must-have Eclipse plug-ins for Flex/Flash Development</title>
		<link>http://dispatchevent.org/mims/pimp-my-clipse-a-list-of-must-have-eclipse-plug-ins-for-flexflash-development/</link>
		<comments>http://dispatchevent.org/mims/pimp-my-clipse-a-list-of-must-have-eclipse-plug-ins-for-flexflash-development/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 16:00:18 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://mimswright.com/blog/?p=216</guid>
		<description><![CDATA[
FlexBuilder may have its ups and downs but it still remains my pick for best AS3/MXML editor on the market (with TextMate not far behind). Part of the beauty of FlexBuilder is that it&#8217;s built on the Eclipse SDK, one of the most versatile and powerful IDEs available, which is not only free and open [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://mimswright.com/blog/wp-content/uploads/2007/12/eclipserims.png' alt='Eclipse Rims' /></p>
<p>FlexBuilder may have its ups and downs but it still remains my pick for best AS3/MXML editor on the market (with <a href="http://macromates.com/">TextMate</a> not far behind). Part of the beauty of FlexBuilder is that it&#8217;s built on the <a href="http://www.eclipse.org/">Eclipse SDK</a>, one of the most versatile and powerful IDEs available, which is not only free and open source, but boasts <a href="http://www.eclipseplugincentral.com/">a wealth of third party plug-ins</a> for every kind of (mostly Java) development. This article will take a look at some must-have plug-ins for doing Flex development as well as some tips for tricking out your development process.</p>
<p>As with all of our entries, your feedback, suggestions, corrections and additions are all more than welcome.</p>
<p><span id="more-216"></span></p>
<p class="disclaimer">Disclaimer: This article applies to the Flex Builder Eclipse Plug-in version, not the standalone version. If you&#8217;re using the standalone version and would like to try these plugins out, I recommend installing the plug-in version. It&#8217;s a little harder to use but I think it&#8217;s more rewarding in the end. Also, this tutorial was written on the Mac version with Eclipse 3.3 and Flex Builder 3 beta 2 so your experience may vary slightly if you&#8217;re using Windows or something else. Furthermore, I am not responsible for any damages or loss of data or anything else that happens as a result of you following the advice in this article &#8211; nothing should go wrong however many plug-ins are buggy and may cause eclipse to perform poorly or crash.</p>
<h3>Installing FlexBuilder Eclipse Plug-in</h3>
<p>To install the FlexBuilder Eclipse Plug-in version you will probably want to first uninstall the FlexBuilder Standalone. You will also need to download and install Eclipse. <strong>Important:</strong> Eclipse is currently in version 3.3.1.1 at the time of writing. If you&#8217;re using FlexBuilder 3, good for you! <a href="http://www.eclipse.org/downloads/download.php?file=//eclipse/downloads/drops/R-3.3.1.1-200710231652/eclipse-SDK-3.3.1.1-macosx-carbon.tar.gz">Go and download the latest version</a> (get the classic distro). However, FlexBuilder 2 does not work on Eclipse 3.3. You&#8217;ll need to download the older version 3.1 or 3.2 of the SDK which are hidden <a href="http://archive.eclipse.org/eclipse/downloads/index.php">deep in the dungeons of the Eclipse Project site</a>.</p>
<p>After Eclipse is installed you can proceed with the installation of the FlexBuilder plug-in. Additional installation instructions can be found on <a href="http://labs.adobe.com/wiki/index.php/Flex_3:Release_Notes#Installation_Instructions">the Adobe Site</a>.</p>
<h3>Installing Plug-ins</h3>
<p>If you take a look at the <a href="http://www.eclipseplugincentral.com/">Eclipse plugin central</a> you&#8217;re liable to notice two things right off the bat. First, there are a ridiculous number of plugins especially for really obscure branches of Java development. Second, the Eclipse site is completely ugly and it&#8217;s often incredibly frustrating to use. I&#8217;ll try to help you get to the juicy bits quickly.</p>
<p>By far the best way to install Eclipse plug-ins is to use <em>update sites</em>. Update sites allow you to select and download plug-in packages directly from the developer from within the Eclipse program. The update site URLs are notoriously difficult to find due to the Eclipse site&#8217;s confusing navigation. For example, I jut tried to get to the update site URL for Europa, a major Eclipse supported plugin, and it took about 4 minutes worth of clicking for me to find it (at best it takes 3 clicks). These elusive links to update sites should, in my opinion, be in big red letters on the front of every project page so in case Eclipse is reading this right now, WTF doodz!?</p>
<p>Once you have the update site URL take the following steps to search the site for updates:</p>
<ol>
<li>Go into eclipse and click on <strong>Help > Software Updates > Find and Install&#8230;</strong> (Help menu? Again, WTF)</li>
<li>Select <strong>Search for new features to install</strong></li>
<li>Click the <strong>next ></strong> button</li>
<li>Click on the <strong>New remote site&#8230;</strong> button</li>
<li>Give the update site a label and paste the update site url. Click ok</li>
<li>Make sure the site you added (and any other sites you want to update) are checked and click the <strong>Finish</strong> button</li>
<li>On the next screen you&#8217;ll see you can choose which features of the plugin you would like to install. For most plugins, you&#8217;ll probably want all of them so check the root folder. <strong>Note:</strong> you may see an error at the top of the window such as <em>FooBar v.0.7 requires plug-in &#8216;org.eclipse.foobar.core&#8217;.</em> If this happens, it can usually be fixed by clicking on the <strong>Select Required</strong> button which will automatically select the required features.</li>
<li>When you&#8217;re done selecting features, click <strong>Next ></strong></li>
<li><strong>ALWAYS CAREFULLY READ EVERY LINE OF THE EULA!</strong> then click <strong>I accept the terms of the license agreements</strong> and click <strong>Next ></strong></li>
<li>Click the <strong>Finish</strong> button. You may be asked again about certain features during installation for which you can click <strong>Install All</strong> to keep going</li>
<li>When the installation is done, restart the Eclipse SDK</li>
</ol>
<p>That&#8217;s it in just 11 tedious steps!</p>
<p>To get updates of already installed plugins choose <strong>Search for updates of the currently installed features</strong> at step 2 and follow the instructions above. If you install a plugin that conflicts with your setup or if you want to temporarily disable or uninstall a plugin, you can always go to <strong>Help > Software Updates > Manage Configuration&#8230;</strong> to manage your environment. Keep in mind that most plugins add new items to <strong>Eclipse preferences</strong>, the <strong>Window > Open Perspective</strong> dialog, the <strong>Window > Show View</strong> dialog or the <strong>File > New</strong> dialog.</p>
<h4>A note about simultaneous releases &#8211; <a href="http://www.eclipse.org/projects/europa.php">Europa</a>, <a href="http://www.eclipse.org/projects/ganymede.php">Ganymede</a>, and <a href="http://www.eclipse.org/projects/callisto.php">Callisto</a></h4>
<p>In 2006 the Eclipse Foundation decided to take ten of the most used plug-ins and wrap them into one release so that the plug-ins would update at the same time as the Eclipse SDK. This project was called Callisto. They considered it a great success so they did it again in 2007 and (confusingly) called it Europa. 2008&#8217;s project is called Ganymede.</p>
<p>Some of the plug-ins listed below are part of the Europa project (currently, the latest full version release). To install these plugins you will want to check the Europa update site which contains several projects but you should select only the ones you want to install.</p>
<h3>Must-have Plug-ins</h3>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>Web Tools Platform (WTP)</td>
</tr>
<tr>
<th>Website</th>
<td><a href="http://www.eclipse.org/webtools/">http://www.eclipse.org/webtools/</a></td>
</tr>
<tr>
<th>Update Site</th>
<td>http://download.eclipse.org/releases/europa/site.xml</td>
</tr>
<tr>
<th>Description</th>
<td>
<p>If you work with Flex or Flash, chances are you&#8217;re making a website. This project provides tools for editing the standard web formats like XHTML.</p>
<p>Mylyn is part of the <a href="http://www.eclipse.org/projects/europa.php">Europa</a> simultaneous release.</p>
</td>
</tr>
</table>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>Mylyn</td>
</tr>
<tr>
<th>Website</th>
<td><a href="http://www.eclipse.org/mylyn/">http://www.eclipse.org/mylyn/</a></td>
</tr>
<tr>
<th>Update Site</th>
<td>http://download.eclipse.org/releases/europa/site.xml</td>
</tr>
<tr>
<th>Description</th>
<td>
<p>Mylyn lets you code using the concept of task-oriented development. It is built to help you focus on a single task by obscuring unused classes and hooking in with most of the commonly used bug-tracking tools. Especially cool if you use a program like TRAC.</p>
<p>Mylyn is part of the <a href="http://www.eclipse.org/projects/europa.php">Europa</a> simultaneous release.</p>
</td>
</tr>
</table>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>CVS &amp; ANT</td>
</tr>
<tr>
<th>Website</th>
<td>N/A</td>
</tr>
<tr>
<th>Update Site</th>
<td>N/A</td>
</tr>
<tr>
<th>Description</th>
<td>
<p>Technically, not a plugin. CVS support and ANT support are built into the latest version of Eclipse so you won&#8217;t need to install these separately. However, they function like plugins and they are very useful so I think they deserve a mention here.</p>
<p>CVS support allows you to manage <a href="http://www.nongnu.org/cvs/">CVS</a> (Concurrent Versioning System) Repositories and make checkouts and changes from within Eclipse. Personally I prefer SVN for versioning (see also <a href="#subclipse">Subclipse</a>) but sometimes it&#8217;s not up to me and this functionality is quite useful.</p>
<p><a href="http://ant.apache.org/">ANT</a> is a tool you can use to create build scripts for your Flex project or for any other language. This is a must-have for larger projects with complicated deploy folders. More info on using ANT and Flex can be found at <a href="http://labs.adobe.com/wiki/index.php/Flex_Ant_Tasks">Adobe Labs</a> and in the <a href="http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00000368.html">Flex 2 docs</a>.</p>
</td>
</tr>
</table>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>Snippets</td>
</tr>
<tr>
<th>Website</th>
<td>N/A</td>
</tr>
<tr>
<th>Update Site</th>
<td>N/A</td>
</tr>
<tr>
<th>Description</th>
<td>
<p>OK. To be honest, I&#8217;m not sure how you install this one. I think it&#8217;s automatically installed as part of the <a href="http://www.eclipse.org/webtools/">Web Tools Project</a> (WTP) or maybe <a href="http://www.eclipse.org/pdt/">PHP Development Tools</a> (PDT) also mentioned in this post. Either way, once it&#8217;s installed you can access it through the Window > Show View menu item.</p>
<p>Snippets lets you define code templates that let you add big chunks of code to a class with a few clicks. You can define variables that appear in the code as well. For example, you may create a snippet that creates a private variable and a public getter and setter and only pass in the variable name and the type. Pretty useful, but not as good as <a href="http://macromates.com/">TextMate</a>.</p>
</td>
</tr>
</table>
<p><a name="subclipse"></a></p>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>Subclipse</td>
</tr>
<tr>
<th>Website</th>
<td><a href="http://subclipse.tigris.org/">http://subclipse.tigris.org/</a></td>
</tr>
<tr>
<th>Update Site</th>
<td>http://subclipse.tigris.org/update_1.2.x</td>
</tr>
<tr>
<th>Description</th>
<td>A plugin that lets you manage a list of Subversion (SVN) repositories, check out directly from the list, and update, commit, etc. the files in the repository straight from your navigation view in Eclipse. So basically like <a href="http://tortoisesvn.tigris.org/">Tortoise SVN</a> for Eclipse.</td>
</tr>
</table>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>TODO / FIXME Task Plugin</td>
</tr>
<tr>
<th>Website</th>
<td><a href="http://www.richinternet.de/blog/index.cfm?entry=911D4B57-0F0D-5A73-AF6F4D4D04099757">http://www.richinternet.de/blog/index.cfm?entry=911D4B57-0F0D-5A73-AF6F4D4D04099757</a></td>
</tr>
<tr>
<th>Update Site</th>
<td>N/A &#8211; see website</td>
</tr>
<tr>
<th>Description</th>
<td>
<p>This is a simple little tool that tracks all of your TODO or FIXME comments in Eclipse&#8217;s Tasks view. There&#8217;s no update site so you&#8217;ll have to follow the instructions on the webpage.</p>
</td>
</tr>
</table>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>JSEclipse</td>
</tr>
<tr>
<th>Website</th>
<td><a href="http://labs.adobe.com/technologies/jseclipse/">http://labs.adobe.com/technologies/jseclipse/</a></td>
</tr>
<tr>
<th>Update Site</th>
<td>http://download.macromedia.com/pub/labs/jseclipse/autoinstall</td>
</tr>
<tr>
<th>Description</th>
<td>Adobe&#8217;s official JavaScript plugin for Eclipse with support for FlexBuilder, popular JS frameworks, and JavaDoc.</td>
</tr>
</table>
<p><!-- ********************** --></p>
<h3>Notable Mention</h3>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>Eclipse Regular Expression Tester</td>
</tr>
<tr>
<th>Website</th>
<td><a href="http://www.brosinski.com/regex/">http://www.brosinski.com/regex/</a></td>
</tr>
<tr>
<th>Update Site</th>
<td>http://brosinski.com/regex/update</td>
</tr>
<tr>
<th>Description</th>
<td>This is a tool that will help you visualize Regular Expressions which can be very confounding to look at even for people who are experienced with using them.</td>
</tr>
</table>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>Ruby Development Tools (RDT)</td>
</tr>
<tr>
<th>Website</th>
<td><a href="http://rubyeclipse.sourceforge.net/">http://rubyeclipse.sourceforge.net/</a></td>
</tr>
<tr>
<th>Update Site</th>
<td>http://updatesite.rubypeople.org/release</td>
</tr>
<tr>
<th>Description</th>
<td>If you develop in Ruby, you&#8217;ll probably want this. Also see PDT below.</td>
</tr>
</table>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>PHP Development Tools (PDT)</td>
</tr>
<tr>
<th>Website</th>
<td><a href="http://www.eclipse.org/pdt/">http://www.eclipse.org/pdt/</a></td>
</tr>
<tr>
<th>Update Site</th>
<td>http://download.eclipse.org/tools/pdt/updates/</td>
</tr>
<tr>
<th>Description</th>
<td>If you develop in PHP, you&#8217;ll probably want this. Also see RDT above.</td>
</tr>
</table>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>Aptana</td>
</tr>
<tr>
<th>Website</th>
<td><a href="http://www.aptana.com/">http://www.aptana.com/</a></td>
</tr>
<tr>
<th>Update Site</th>
<td>http://update.aptana.com/update/3.2/</td>
</tr>
<tr>
<th>Description</th>
<td>
<p>A full featured IDE for working on web apps. There is also a standalone version. Aptana looks very promising, however, I disabled it since it seemed to be conflicting with other plugins in my Eclipse setup.</p>
<p>Roger kinda likes it though:</p>
<blockquote><p>aptana is great because it is an integrated development environment, unlike a standalone text editor. Its integrated Javascript contextual completion and compatibility matrices are lifesavers. It plays nicely with other eclipse editors and uses a plugin architecture to support not only [X]HTML and Javascript, but also RoR and PHP.</p></blockquote>
</td>
</tr>
</table>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>FDT 3.0</td>
</tr>
<tr>
<th>Website</th>
<td><a href="http://fdt.powerflasher.com/">http://fdt.powerflasher.com/</a></td>
</tr>
<tr>
<th>Update Site</th>
<td>N/A</td>
</tr>
<tr>
<th>Description</th>
<td>FDT has a great track record and the Enterprise edition of FDT 3.0 could be the first third-party FlexBuilder competitor worth considering. However, with the price of the package now approaching the nine-hundred dollar mark thanks to our failing currency, this is a fairly high-risk alternative.</td>
</tr>
</table>
<table class="plugin" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Plugin</th>
<td>Eclipse Monkey (aka project dash)</td>
</tr>
<tr>
<th>Website</th>
<td><a href="http://www.eclipse.org/dash/">http://www.eclipse.org/dash/</a></td>
</tr>
<tr>
<th>Update Site</th>
<td>http://download.eclipse.org/technology/dash/update/</td>
</tr>
<tr>
<th>Description</th>
<td>Allows you to create scripts to automate Eclipse itself using JS. I haven&#8217;t used this but it sounds interesting.</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/pimp-my-clipse-a-list-of-must-have-eclipse-plug-ins-for-flexflash-development/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>
