<?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>Sean Monahan &#187; Code</title>
	<atom:link href="http://seanmonahan.org/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanmonahan.org</link>
	<description></description>
	<lastBuildDate>Mon, 09 Aug 2010 01:42:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Introducing a Tile Strip Utility for Flixel: Stripper</title>
		<link>http://seanmonahan.org/2010/05/27/introducing-a-tile-strip-utility-for-flixel-stripper/</link>
		<comments>http://seanmonahan.org/2010/05/27/introducing-a-tile-strip-utility-for-flixel-stripper/#comments</comments>
		<pubDate>Fri, 28 May 2010 05:47:03 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Gaming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flixel]]></category>
		<category><![CDATA[Tile Strips]]></category>
		<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://seanmonahan.org/?p=534</guid>
		<description><![CDATA[Stripper is a simple utility for quickly gathering a bunch of images into a precise tile strip for Flixel-base games. Currently an alpha, you can watch a demo of Stripper here and read more + follow progress here.]]></description>
			<content:encoded><![CDATA[<p>Stripper is a simple utility for quickly gathering a bunch of images into a precise tile strip for Flixel-base games.  Currently an alpha, you can watch a demo of Stripper <a href="http://vimeo.com/12100683" title="Video Demo of Stripper">here</a> and read more + follow progress <a href="/stripper-a-tile-strip-utility-for-flixel" title="Read more about Stripper">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanmonahan.org/2010/05/27/introducing-a-tile-strip-utility-for-flixel-stripper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Defuse World Editor</title>
		<link>http://seanmonahan.org/2010/05/14/defuse-world-editor/</link>
		<comments>http://seanmonahan.org/2010/05/14/defuse-world-editor/#comments</comments>
		<pubDate>Sat, 15 May 2010 02:07:12 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Gaming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Defuse]]></category>
		<category><![CDATA[tile editor]]></category>

		<guid isPermaLink="false">http://seanmonahan.org/?p=519</guid>
		<description><![CDATA[I recently added a page to this site for Defuse World Editor, a 2D tile-based editor for games. Presently the editor is closely tied to Defuse, a 2D action-puzzle-platformer I&#8217;m finishing up for release this summer, but I plan to cut that cord and make it a much more reusable and general purpose level editor. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently added a page to this site for <a href="/projects/defuse-world-editor-a-tile-based-2d-level-editor/" title="Defuse World Editor">Defuse World Editor</a>, a 2D tile-based editor for games.  Presently the editor is closely tied to Defuse, a 2D action-puzzle-platformer I&#8217;m finishing up for release this summer, but I plan to cut that cord and make it a much more reusable and general purpose level editor.</p>
<p><span id="more-519"></span></p>
<p>Follow the project <a href="/projects/defuse-world-editor-a-tile-based-2d-level-editor/" title="Defuse World Editor">here</a> and check out the first <a href="http://vimeo.com/11417133" title="Defuse World Editor Demo Video #1">demo vid</a> on Vimeo.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanmonahan.org/2010/05/14/defuse-world-editor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UPDATE: Adding Build Paths to Flex Projects on Windows 7 64-bit</title>
		<link>http://seanmonahan.org/2009/12/05/adding-build-paths-to-flex-projects-on-windows-7-64-bit/</link>
		<comments>http://seanmonahan.org/2009/12/05/adding-build-paths-to-flex-projects-on-windows-7-64-bit/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 01:12:28 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Build Path]]></category>
		<category><![CDATA[Flex Builder 3]]></category>
		<category><![CDATA[Windows 7 64-bit]]></category>

		<guid isPermaLink="false">http://seanmonahan.org/?p=435</guid>
		<description><![CDATA[I recently upgraded to Windows 7 x64 from Windows Vista x64 and I must say I&#8217;m loving it! However, much like Vista x64 before it Win7 x64 doesn&#8217;t play nice with Flex Builder. I still have issues with blank dialogs (for which I found a work around) but now I have an issue with adding [...]]]></description>
			<content:encoded><![CDATA[<p>I recently upgraded to Windows 7 x64 from Windows Vista x64 and I must say I&#8217;m loving it!  However, much like Vista x64 before it Win7 x64 doesn&#8217;t play nice with Flex Builder.  I still have issues with blank dialogs (for which I found a <a href="http://seanmonahan.org/2009/06/12/blank-project-properties-in-flex-builder-3-on-windows-vista-64-bit/">work around</a>) but now I have an issue with adding build paths.<br />
<span id="more-435"></span><br />
When this problem first reared it&#8217;s head I tried looking at the project meta files and was unable to get a fix.  Since I also work on a MacBook Pro where everything works fine, I left it be until I saw <a href="http://www.actionscript.org/forums/showthread.php3?p=947463&#038;posted=1#post947463">this</a> post on the actionscript.org forum.  While posting a response detailing my experience with the bug it occurred to me that this all worked fine on Mac OS so I should probably have the proper build path entries in my project meta files on my Mac.</p>
<p>Sure enough the entries were there:</p>
<pre>
&lt;compilerSourcePath&gt;
      &lt;compilerSourcePathEntry kind="1" linkType="1" path="properties"/&gt;
      &lt;compilerSourcePathEntry kind="1" linkType="1" path="locale/{locale}"/&gt;
&lt;/compilerSourcePath&gt;
</pre>
<p>At this point I&#8217;m not really sure what the <tt>kind</tt> and <tt>linkType</tt> properties are for other than the fact that <tt>1</tt> is the default for both of them.  I&#8217;ll post back as I found out more.  In the meantime this has allowed me to add build paths to my projects with Flex Builder 3 on Windows 7 x64.</p>
<p>UPDATE.</p>
<p>Seems turning off the Logitech software I use for my mouse and keyboard resolves this problem altogether.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanmonahan.org/2009/12/05/adding-build-paths-to-flex-projects-on-windows-7-64-bit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Restoring a Minimized AIR App From the Mac OS Dock</title>
		<link>http://seanmonahan.org/2009/12/02/restoring-a-minimized-air-app-from-the-mac-os-dock/</link>
		<comments>http://seanmonahan.org/2009/12/02/restoring-a-minimized-air-app-from-the-mac-os-dock/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 17:16:38 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Mac OS]]></category>

		<guid isPermaLink="false">http://seanmonahan.org/?p=433</guid>
		<description><![CDATA[Here&#8217;s a link to a post I did over at the BKWLD blog about making AIR apps more seamless on Mac OS.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a <a href="http://bkwld.com/blog/2009/11/restoring-a-minimized-air-app-from-the-mac-os-dock/">link</a> to a post I did over at the BKWLD blog about making AIR apps more seamless on Mac OS.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanmonahan.org/2009/12/02/restoring-a-minimized-air-app-from-the-mac-os-dock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Application Menus in Mac OSX with Adobe AIR</title>
		<link>http://seanmonahan.org/2009/11/15/creating-application-menus-in-mac-osx-with-adobe-air/</link>
		<comments>http://seanmonahan.org/2009/11/15/creating-application-menus-in-mac-osx-with-adobe-air/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 19:46:36 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Application Menu]]></category>
		<category><![CDATA[Mac OS]]></category>

		<guid isPermaLink="false">http://seanmonahan.org/?p=430</guid>
		<description><![CDATA[I recently wrote a post over on the Buk Life blog about creating native menus with Adobe AIR in Mac OS. The emphasis of the article is making the &#8220;application name&#8221; menu (e.g., &#8220;Safari&#8221; for the Safari browser) look like it belongs when creating customized application menus. You can read the full article here: Creating [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wrote a post over on the <a href="http://bkwld.com/blog/">Buk Life</a> blog about creating native menus with Adobe AIR in Mac OS.  The emphasis of the article is making the &#8220;application name&#8221; menu (e.g., &#8220;Safari&#8221; for the Safari browser) look like it belongs when creating customized application menus.</p>
<p>You can read the full article here: <a href="http://bkwld.com/blog/2009/11/creating-application-menus-in-mac-osx-with-adobe-air/">Creating Application Menus in Mac OSX with Adobe AIR</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanmonahan.org/2009/11/15/creating-application-menus-in-mac-osx-with-adobe-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing the Font Size in Flex Builder</title>
		<link>http://seanmonahan.org/2009/04/21/changing-the-font-size-in-flex-builder/</link>
		<comments>http://seanmonahan.org/2009/04/21/changing-the-font-size-in-flex-builder/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 22:54:11 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flex Builder]]></category>

		<guid isPermaLink="false">http://seanmonahan.org/?p=397</guid>
		<description><![CDATA[I&#8217;ve had to reset the font size in Flex Builder a few times now and each time I forget, not because it&#8217;d been so long since I&#8217;d last changed the font size, but because the setting is buried away, hidden from view. To change the font size in Flex Builder click Window > Preferences&#8230;. In [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had to reset the font size in Flex Builder a few times now and each time I forget, not because it&#8217;d been so long since I&#8217;d last changed the font size, but because the setting is buried away, hidden from view.</p>
<p>To change the font size in Flex Builder click Window > Preferences&#8230;.  In the dialog that pops up click General > Appearance > Colors and Fonts and expand the Basic rollout.  In the Basic rollout there are a bunch of options, click Text Font and then click the Change&#8230; button that appears.  It should be smooth sailing from here.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanmonahan.org/2009/04/21/changing-the-font-size-in-flex-builder/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Preventing Users from Accidently Navigating Away From Your Flex App</title>
		<link>http://seanmonahan.org/2009/03/19/preventing-users-from-accidently-navigating-away-from-your-flex-app/</link>
		<comments>http://seanmonahan.org/2009/03/19/preventing-users-from-accidently-navigating-away-from-your-flex-app/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 01:55:08 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[onbeforeunload]]></category>

		<guid isPermaLink="false">http://seanmonahan.org/?p=368</guid>
		<description><![CDATA[One of the downsides to creating Rich Internet Applicationss is that they defy the standard methods for interacting with websites &#8212; the refresh, back and forward buttons have no real place in an Flex application.  As a developer you probably understand that clicking refresh or back is a no-no but you users aren&#8217;t likely to [...]]]></description>
			<content:encoded><![CDATA[<p>One of the downsides to creating Rich Internet Applicationss is that they defy the standard methods for interacting with websites &#8212; the refresh, back and forward buttons have no real place in an Flex application.  As a developer you probably understand that clicking refresh or back is a no-no but you users aren&#8217;t likely to be as savvy.  This article will describe a method you can employ to prompt users with a confirmation dialog when they attempt to navigate away from you Flex app.  <span id="more-368"></span> For this article I assume you are not using <a title="About Deep Linking" href="http://livedocs.adobe.com/flex/3/html/help.html?content=deep_linking_2.html">deep linking</a> in your Flex application as I&#8217;m not currently using it with any of my projects so I cannot speak to using it in this scenario.  I&#8217;ve also only tested this with the Windows versions of Internet Explorer 7, Firefox 3.x, Chrome 1 and Safari 4 beta so if you&#8217;re using anything else your mileage may vary (will test with Mac browsers once I fix my Flash Player install).</p>
<p>With the disclaimer out of the way we&#8217;ll get down to business.  Our goal here is to produce a close confirmation popup when a user accidentally attempts to navigate away from our Flex app.  Examples of &#8220;navigating away from our Flex app&#8221; include: clicking the refresh, back or forward button, clicking a bookmark or favorite, or typing a new url in the address bar.  Additionally we&#8217;ll disable the prompt when the user intentionally navigates away from our Flex app; when logging out for example.  To accomplish this we&#8217;ll make use of the Javascript onbeforeunload event and Flex/Flash&#8217;s ExternalInterface package.</p>
<p>At this point I feel it&#8217;s important to note that doing what are about to implement is generally considered bad form for websites.  If I, as a user, want to leave a page I&#8217;d damn well better be able to with no hassle.  A Flex app is usually not a typical website however, rather it is an application running inside a web browser and when you close an application like Word with unsaved data you always get a confirmation dialog.</p>
<p>It&#8217;s my opinion that displaying a close confirmation for a Flex app is good form for two reasons.  The first is that RIAs are meant to be similar to desktop applications and any half decent desktop application is going to have you confirm closing the application if you have unsaved information.  The second is that, in being more like a desktop app, an RIA subverts the way users typically interact with web sites and web apps.  For most Flex apps the back and refresh buttons can cause havoc so throwing up a confirmation dialog when these buttons are clicked can enhance your application.</p>
<p>So we&#8217;ve made up our minds that we&#8217;re adding the close confirmation popup now lets get to it!</p>
<h3>The Javascript</h3>
<p>The first thing we need is some Javascript that will allow us to work with the onbeforeunload event.  Specifically we&#8217;ll need:</p>
<ul>
<li>A flag to indicate whether or not the popup should be displayed</li>
<li>A variable to hold the text we want displayed in the popup</li>
<li>A function to set the flag</li>
<li>A function to set the prompt text</li>
</ul>
<p>Here&#8217;s my Javascript object, FlexOnBeforeUnload that encapsulates all of this:</p>
<pre>
<pre class="brush: jscript;">

var FlexOnBeforeUnload = {

   /**
    * Flag indicating the user should be prompted each
    * time they attempt to navigate away from or refresh
    * the Admin HTML page.
    */
   prompt: true,

   promptText: &quot;Refreshing or leaving this page will cause you &quot;
             + &quot;to lose any unsaved data.\n&quot;
             + &quot;Are you sure you want to leave?&quot;,

   /**
    * Sets the value of &quot;prompt&quot;
    */
   setPrompt: function (value) {
      if (value) {
         FlexOnBeforeUnload.prompt = true;
      } else if (!value) {
         FlexOnBeforeUnload.prompt = false;
      }
   }

   /**
    * Sets the value of &quot;promptText&quot;
    */
   setPromptText: function (value) {
      FlexOnBeforeUnload.promptText = value;
   }
};
</pre>
</pre>
<p>Using Javascript we can access prompt and priompText directly however the ExternalInterface package in Flex only allows you to make calls to Javascript functions &#8212; you cannot use it to access variables directly.  Besides accessor functions are good practice.</p>
<p>SetPrompt will take a boolean value and assign it to prompt.  Setting prompt to true will cause the close confirmation to be displayed when a user attempts to navigate away from your Flex app.  Setting prompt to false will allow users to navigate away without any nagging.</p>
<p>SetPromptText will allow you to change the text displayed in your confirmation dialog.  Unfortunately you have very little control over the text displayed in the confirmation dialog.  The dialog will always display &#8220;Are you sure you want to navigate away from this page?&#8221; and &#8220;Press OK to continue, or Cancel to stay on the current page.&#8221; along with the OK and Cancel buttons.  The only thing you can customize is the text that appears between &#8220;Are you sure&#8230;&#8221; and &#8220;Press OK&#8230;&#8221;.</p>

<a href="http://seanmonahan.org/wp-content/gallery/flex-close-confirmation/close-confirm.png" title="" class="thickbox" rel="singlepic46" >
	<img class="ngg-singlepic" src="http://seanmonahan.org/wp-content/gallery/cache/46__x_close-confirm.png" alt="close-confirm.png" title="close-confirm.png" />
</a>

<p>In the above pic you can see that &#8220;Refreshing or leaving this page will cause you to lose any unsaved data.  Are you sure you want to leave?&#8221;, the default promptText, is displayed in the close dialog.  Now that we have our Javascript object we&#8217;ll save it in a file called flex-onbeforeunload.js.</p>
<p>Now open up your HTML wrapper (the HTML page that loads your Flex app) and include flex-onbeforeunload.js in the head:</p>
<pre class="brush: xml;">

&lt;!-- Assumes the JS file is located in the same folder as the wrapper. --&gt;
&lt;script src=&quot;flex-onbeforeunload.js&quot; language=&quot;javascript&quot;&gt;
&lt;/script&gt;
</pre>
<p>After that you are ready to setup the onbeforeunload event handler.  In a script block beneath the include we just added add the following:</p>
<pre>
<pre class="brush: jscript;">

window.onbeforeunload = function(e) {
   if (FlexOnBeforeUnload.prompt) {
      return FlexOnBeforeUnload.promptText;
   }
}
</pre>
</pre>
<p>This code will be executed prior to the page being unloaded (onbeforeunload even).  If FlexOnBeforeUnload.prompt is true the close confirmation will be displayed with our promptText.  If FlexOnBeforeUnload.prompt is false the function returns nothing and no confirmation will be shown.</p>
<h3>The Actionscript</h3>
<p>Since the default for FlexOnBeforeUnload.prompt is true the close confirmation dialog will always be shown unless we take some action to prevent it.  Enter <a href="http://livedocs.adobe.com/flex/3/langref/flash/external/ExternalInterface.html">ExternalInterface</a>, a class used to facilitate communication between Actionscript and Flash Player and the HTML wrapper.  In other words, ExternalInterface allows Actionscript to talk with Javascript and vice versa, though in our situation we&#8217;ll only being going from Actionscript to Javascript.</p>
<p>For our purposes we are interested in two parts of ExternalInterface, the call method and the available property.  ExternalInterface.available &#8220;[i]ndicates whether this player is in a container that offers an external interface.&#8221;  In English, if ExternalInterface.available is true we can use ExternalInterface.  ExternalInterface.call allows us to call Javascript functions in the wrapper.  To use ExternalInterface.call you pass in the name of the Javascript function as a string and then any parameters the Javascript function takes as a comma-separated list.</p>
<p>Earlier I gave the example of logout as a situation where you would probably not want to show a close confirmation popup.  Using ExternalInterface you can disable the confirmation for situations such as this.  To disable the confirmation popup add the following to your logout code in Flex Builder:</p>
<pre>
<pre class="brush: jscript;">

// Make sure ExternalInterface is available
if (ExternalInterface.available)
{
   // Set prompt to false, disabling the close confirmation
   ExternalInterface.call(&quot;FlexOnBeforeUnload.setPrompt&quot;, false);
}
else
{
   // Optionally handle the situation where ExternalInterface
   // is not available.
}
</pre>
</pre>
<p>This will set the value of FlexOnBeforeUnload.prompt to false, disabling the close confirmation.  Similarly you can change the prompt text:</p>
<pre>
<pre class="brush: jscript;">

// Make sure ExternalInterface is available
if (ExternalInterface.available)
{
   // Set prompt to false, disabling the close confirmation
   ExternalInterface.call(&quot;FlexOnBeforeUnload.setPromptText&quot;,
                                &quot;Different prompt text.&quot;);
}
else
{
   // Optionally handle the situation where ExternalInterface
   // is not available.
}
</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanmonahan.org/2009/03/19/preventing-users-from-accidently-navigating-away-from-your-flex-app/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>A Flex Shake Effect</title>
		<link>http://seanmonahan.org/2009/02/14/a-flex-shake-effect/</link>
		<comments>http://seanmonahan.org/2009/02/14/a-flex-shake-effect/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 17:14:54 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flex Effects]]></category>

		<guid isPermaLink="false">http://seanmonahan.org/?p=245</guid>
		<description><![CDATA[When I first got my MacBook Pro one of the first things I did was&#8230;type my password incorrectly. When this happens Mac OS provides some great visual feeback with a shaking effect that simultaneously indicates something went wrong and shrugs off the password much like how dogs dry themselves off after a swim.  To me, [...]]]></description>
			<content:encoded><![CDATA[<p>When I first got my MacBook Pro one of the first things I did was&#8230;type my password incorrectly. When this happens Mac OS provides some great visual feeback with a shaking effect that simultaneously indicates something went wrong and shrugs off the password much like how dogs dry themselves off after a swim.  To me, this was very cool.  Now, in the great tradition of the web I&#8217;m ripping off Apple&#8217;s idea to give you a <a title="Flex Shake Effect." href="/projects/flex-shake-effect/">Flex shake effect</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanmonahan.org/2009/02/14/a-flex-shake-effect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Flex List to List Component</title>
		<link>http://seanmonahan.org/2009/01/09/a-flex-list-to-list-component/</link>
		<comments>http://seanmonahan.org/2009/01/09/a-flex-list-to-list-component/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 23:43:41 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Component]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[List to List]]></category>

		<guid isPermaLink="false">http://seanmonahan.org/?p=226</guid>
		<description><![CDATA[On a recent Flex project I needed a component that would allow me to move selected items in one list to another list.  A Google search for &#8220;flex list to list component&#8221; turned up nothing, nor did &#8220;flex enhanced list component&#8221;.  Undaunted I decided to roll my own which I am now sharing with the [...]]]></description>
			<content:encoded><![CDATA[<p>On a recent Flex project I needed a component that would allow me to move selected items in one list to another list.  A Google search for &#8220;flex list to list component&#8221; turned up nothing, nor did &#8220;flex enhanced list component&#8221;.  Undaunted I decided to roll my own which I am now sharing with the world.</p>
<p><span id="more-226"></span>The component has a robust feature set providing multiple move options and customization for nearly everything.  I&#8217;ve created a project page for this component <a href="/projects/flex-list-to-list-component/">here</a>.  There you can find a demo and download the source for use in your own projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanmonahan.org/2009/01/09/a-flex-list-to-list-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create HTML Forms with Object-Oriented PHP</title>
		<link>http://seanmonahan.org/2008/12/18/create-html-forms-with-object-oriented-php/</link>
		<comments>http://seanmonahan.org/2008/12/18/create-html-forms-with-object-oriented-php/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 23:23:04 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[HTML Forms]]></category>
		<category><![CDATA[Object-Oriented]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP5]]></category>

		<guid isPermaLink="false">http://seanmonahan.org/?p=122</guid>
		<description><![CDATA[One of the things I really dislike about PHP is it&#8217;s reliance on spaghetti code.  Every PHP developer has had to deal with &#60;?php ?&#62; tags strewn about HTML in a seeming mess.  The worst situation is updating someone else&#8217;s code.  Often it takes longer to decipher everything than it does to make the actual [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I really dislike about PHP is it&#8217;s reliance on spaghetti code.  Every PHP developer has had to deal with &lt;?php ?&gt; tags strewn about HTML in a seeming mess.  The worst situation is updating someone else&#8217;s code.  Often it takes longer to decipher everything than it does to make the actual update.<br />
<span id="more-122"></span><br />
I&#8217;ve been working on a project that takes a lot of user input from HTML forms and I decided at the beginning that I was not going to deal with a bunch of spaghetti code to get things done.  Rather I wrote a serious of form classes in PHP5.  These classes allow me to write HTML forms without having to write a single line of HTML &#8212; everything is handled in PHP and it has definitely made life easier.</p>
<p>Now I&#8217;m going to share the love so no one else has to suffer through a mess of convoluted code.</p>
<h3>The Classes</h3>
<p>My form class libary has seven classes.  Each distinct form element type (e.g., &lt;input&gt;, &lt;select&gt;, etc.) is represented by its own class.  All these elements are then pulled together in the Form class that handles the actual construction and ouputting of the form to the screen.</p>
<p>Download the Form class library <a href="http://seanmonahan.org/wp-content/uploads/2008/12/formclasslibrary.zip">here</a>.</p>
<p>See the complete documentation for the Form class library <a href="http://seanmonahan.org/code/php/docs">here</a>.</p>
<p>Download the examples <a href="http://seanmonahan.org/wp-content/uploads/2008/12/formexamples.zip">here</a>.</p>
<h3>The Examples</h3>
<p>So, you&#8217;re thinking, &#8220;this is cool, but can I see it in action?&#8221; Just read on.</p>
<h4>A Simple Form</h4>
<p>The first example is a simple form with one text input and a submit button.</p>
<pre class="brush: php;">

// Create a new Form object

$form = new Form(&quot;ExampleForm&quot;);

// Add a text input

$form-&gt;addField(new FormInput(&quot;&quot;, &quot;text&quot;, &quot;firstname&quot;, &quot;What is your name?&quot;));

// Add a submit button

$form-&gt;addField(new FormInput(&quot;Submit&quot;, &quot;submit&quot;, &quot;submit&quot;));

// Print the form to the screen

$form-&gt;printForm();
</pre>
<p><a href="http://seanmonahan.org/code/php/examples/form/SimpleForm.php" target="_blank">See the example</a> in action.</p>
<h4>A Simple Form with a Select</h4>
<p>The second example adds a form select (drop down) menu, sets the default item in the select menu and shows off a different way to print forms.</p>
<pre class="brush: php;">

// Create a new Form object
$form = new Form(&quot;ExampleForm&quot;);

// Add a text input
$form-&gt;addField(new FormInput(&quot;&quot;, &quot;text&quot;, &quot;firstname&quot;, &quot;What is your name?&quot;));

// Create some data for our select.
$genders = array();

$genders[] = array(&quot;value&quot; =&gt; &quot;M&quot;, // The value your script will see when the form is submitted.
&quot;name&quot; =&gt; &quot;Man&quot;, // The name that will be displayed to users.
&quot;selected&quot; =&gt; false);

$genders[] = array(&quot;value&quot; =&gt; &quot;W&quot;,
&quot;name&quot; =&gt; &quot;Woman&quot;,
&quot;selected&quot; =&gt; true); // Set this item to be selected by default

// Create a select.
$genderSelect = new FormSelect($genders, &quot;gender&quot;, &quot;Your are a: &quot;);

// Add our select
$form-&gt;addField($genderSelect);

// Add the submit button.
$form-&gt;addField(new FormInput(&quot;Submit&quot;, &quot;submit&quot;, &quot;submit&quot;));

// Save the form as an HTML string.
$html = $form-&gt;buildForm();

// Print the form later.
echo $html;
</pre>
<p><a href="http://seanmonahan.org/code/php/examples/form/SimpleFormWithSelect.php" target="_blank">See the example</a> in action.</p>
<h4>A Less Simple Form with TextArea</h4>
<p>This next example adds a textarea and provides some default text for it as well as the number of columns and rows.</p>
<pre class="brush: php;">

// Create the text area.
$defaultText = &quot;Tell us about yourself.  In 500 words or less.&quot;;
$textarea = new FormTextArea($defaultText, &quot;biography&quot;);

// You can also set properties like this.
$textarea-&gt;setColumns(20);
$textarea-&gt;setRows(5);

// Add the text area.
$form-&gt;addField($textarea);
</pre>
<p><a href="http://seanmonahan.org/code/php/examples/form/SimpleFormWithTextarea.php" target="_blank">See the example</a> in action.</p>
<h4>Organize Things with Separators</h4>
<p>Our example form is starting to get big.  Time to bring some organization into the mix.  Enter separators.  Separtors are purely organizational elements and will not be submitted along with your form.  They simple allow us to visually break up the form so it&#8217;s easier to use.</p>
<pre class="brush: php;">

// Add a separator with the text &quot;Bio&quot;

$form-&gt;addField(new FormSeparator(&quot;Bio&quot;)); // Want the separator without any text?  Just take out &quot;Bio&quot; and you've got it.
</pre>
<p><a href="http://seanmonahan.org/code/php/examples/form/SimpleFormWithSeparators.php" target="_blank">See the example</a> in action.</p>
<h4>Block Bots with CAPTCHA</h4>
<p>The final example adds CAPTCHA to our form.  This class uses Securimage CAPTCHA and you&#8217;ll need to download it from <a href="http://www.phpcaptcha.org/" target="_blank">here</a> if you want to use the CAPTCHA features of this class library.  The FormCaptcha object is a little more complicated than the rest so it&#8217;s easier to create a new object and set the properties afterward.</p>
<pre class="brush: php;">

// Create a new FormCaptcha object.
// NOTE: the source you pass to the contructor is the URI.  In other words,
// you could slap http://www.seanmonahan.org on front of the source and find that script.
$captcha = new FormCaptcha(&quot;/code/php/examples/form/Captcha/securimage_show.php&quot;);

// Position the reload text to be placed after the image.
$captcha-&gt;setReloadLocation(&quot;AfterImage&quot;);

// Set the label for the CAPTCHA input field.
$captcha-&gt;setLabel(&quot;Prove you aren't a bot.&quot;);

// Add the CAPTCHA to the form.
$form-&gt;addField($captcha);
</pre>
<p><a href="http://seanmonahan.org/code/php/examples/form/SimpleFormWithCaptcha.php" target="_blank">See the example</a> in action.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanmonahan.org/2008/12/18/create-html-forms-with-object-oriented-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
