<?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>Meek Geek</title>
	<atom:link href="http://meekgeek.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://meekgeek.com</link>
	<description>Joel Caballero</description>
	<lastBuildDate>Fri, 20 May 2011 23:48:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>AS3 Finite State Machine</title>
		<link>http://meekgeek.com/actionscript/as3-finite-state-machine/</link>
		<comments>http://meekgeek.com/actionscript/as3-finite-state-machine/#comments</comments>
		<pubDate>Fri, 20 May 2011 18:35:35 +0000</pubDate>
		<dc:creator>Joel Caballero</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>

		<guid isPermaLink="false">http://meekgeek.com/?p=249</guid>
		<description><![CDATA[Why the heck do we need libraries like this?! The answer is simple, organization. It&#8217;s nice to come back to a project years later and know exactly what&#8217;s going on. Now the concept of a Finite State Machine seemed a bit abstract to me when I first read about it. My research lead me to [...]]]></description>
			<content:encoded><![CDATA[<p>Why the heck do we need libraries like this?!  The answer is simple, organization.  It&#8217;s nice to come back to a project years later and know exactly what&#8217;s going on.  Now the concept of a Finite State Machine seemed a bit abstract to me when I first read about it.  My research lead me to believe it was exactly what I needed.</p>
<p>The need for libraries like this hit home a few days ago when I was building a playlist plugin for OSMF.  The display object I was working with had a bunch of children that came in and out of the screen in an animated fashion.  It occurred to me this display object had more than one state.  An Initial state that shows up when first run, and an open state that happened once I rolled over a hotspot.  </p>
<p>So, I was reminded of a library I built a couple of years ago.  I always meant to share it with the community.  I decided to scavenge around my old files.  Once I found it, I dusted it off and added a couple more things to it. So with out further a due, here it is.</p>
<p><strong>WHAT IS IT?</strong></p>
<p>It&#8217;s a library of code that lets you organize the different states of a class.  I&#8217;ve only ever used it for display object but I guess you could use it for other things as well.  It&#8217;s super simple and easy to follow.  I&#8217;ve also made it as light weight as possible.  There&#8217;s no need to extend your class but I&#8217;ve included two helper classes to do just that.  </p>
<p><strong>HOW TO USE IT</strong></p>
<p>The first thing you need to do is decide your class is in need of state management.  Then create an instance of StateManager and pass it the class you will be managing.  This example will have a simple square on the upper left hand corner.  Later, we&#8217;ll use that square to demonstrate the different states of our Sprite.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.meekgeek.statemachines.finite.manager.StateManager;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> FSMTest extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> square<span style="color: #000000; font-weight: bold;">:</span>Square;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _manager<span style="color: #000000; font-weight: bold;">:</span>StateManager;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> FSMTest<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			square = <span style="color: #0033ff; font-weight: bold;">new</span> Square<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> square <span style="color: #000000;">&#41;</span>
&nbsp;
			_manager = <span style="color: #0033ff; font-weight: bold;">new</span> StateManager<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
&nbsp;
<span style="color: #9900cc; font-weight: bold;">class</span> Square extends <span style="color: #004993;">Sprite</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Square<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x00<span style="color: #000000;">&#41;</span>
		<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Then start adding your states.  In order to do just that, you&#8217;ll have to create a class that extends State.  These state classes will be where all of your management code goes in.  In the background, these state classes will be told what the context ( in our example FSMTest ) will be.  Once added, the StateManager will call three function of that state class.  &#8220;doIntro&#8221;, &#8220;action&#8221;, and &#8220;doOutro&#8221; at different times of the process.  &#8220;doIntro&#8221; gets called at the beginning of the state.  &#8220;Action&#8221; once the &#8220;doIntro&#8221; is complete and &#8220;doOutro&#8221; is called when moving away from a state. In order to move the states along, it&#8217;s your responsibility to dispatch a couple of events to the StateManager.  The State class, which you have extended has a few helper methods to help you do this.  We&#8217;ll go over that in just a bit.</p>
<p>I like to keep the states of my display in a separate folder.  So, first create a states folder next to your display class.  Then create your InitState that extends State.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> states
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.meekgeek.statemachines.finite.states.State;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> InitState extends State
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> InitState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Now lets add some code.  In the Initial State, our square will be centered in the middle of the stage.  So, we add the code to do just that in the &#8220;doIntro&#8221; method.  I&#8217;ll be tweening the square over to the middle with a popular Tween engine, once the animation is complete, I&#8217;ll dispatch my &#8220;StateEvent.ON_INTRO_COMPLETE&#8221; StateEvent.  I can do this by just calling the protected function &#8220;signalIntroComplete&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> states
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.greensock.TweenMax;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.meekgeek.statemachines.finite.states.State;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> InitState extends State
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> InitState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> doIntro<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			TweenMax.to<span style="color: #000000;">&#40;</span> 
				FSMTest<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span>.context <span style="color: #000000;">&#41;</span>.square, 
				.5, 
				<span style="color: #000000;">&#123;</span> 	
					<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">300</span>, 
					<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">300</span>, 
					onComplete<span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">this</span>.signalIntroComplete 
				<span style="color: #000000;">&#125;</span> 
			<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Once in that state, let&#8217;s color, the square, red.  We only want this to happen once we&#8217;re in the action section of our state.  The action status is given to a state once it&#8217;s &#8220;doIntro&#8221; method is complete and no other states have set.  Otherwise, the action is skipped and &#8220;doOutro&#8221; is called immediately.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> action<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> ct<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">ColorTransform</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ColorTransform</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		ct.<span style="color: #004993;">color</span> = 0xFF0000;
&nbsp;
	FSMTest<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span>.context <span style="color: #000000;">&#41;</span>.square.<span style="color: #004993;">transform</span>.<span style="color: #004993;">colorTransform</span> = ct;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>That&#8217;s it, we&#8217;ve created our first State, now lets add it the StateManager back in our FSMTest class.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">_manager.addState<span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;init&quot;</span>, <span style="color: #0033ff; font-weight: bold;">new</span> InitState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>You&#8217;ll notice, the &#8220;addState&#8221; method accepts three parameters.  The first is a key, this is how we reference our states from now on.  The second is an instance of the state we just created.  The third method is optional, it lets the StateManager know whether or not to use the state you just created as the initial state.  Because we do, we set it to true.</p>
<p>It&#8217;s best practice to set our key as a constant in our State.  This will remove any chance of misspellings in the future.  So lets do that,</p>
<p>Add this to the properties section of your InitState class.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">static <span style="color: #0033ff; font-weight: bold;">public</span> const KEY<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;init&quot;</span>;</pre></div></div>

<p>and change our code in our managed display to represent that.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">_manager.addState<span style="color: #000000;">&#40;</span> InitState.KEY, <span style="color: #0033ff; font-weight: bold;">new</span> InitState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>All we have to do now, is create another state to demonstrate.  The following state moves the square to the right side of the stage at 400px by 100px and colors the square blue. I&#8217;ve called it &#8216;BlueState&#8217;.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> states
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com.greensock.TweenMax;
	<span style="color: #0033ff; font-weight: bold;">import</span> com.meekgeek.statemachines.finite.states.State;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">ColorTransform</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> BlueState extends State
	<span style="color: #000000;">&#123;</span>
		static <span style="color: #0033ff; font-weight: bold;">public</span> const KEY<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">'blue'</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> BlueState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> doIntro<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			TweenMax.to<span style="color: #000000;">&#40;</span> 
				FSMTest<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span>.context <span style="color: #000000;">&#41;</span>.square, 
				.5, 
				<span style="color: #000000;">&#123;</span> 	
					<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">400</span>, 
					<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">100</span>, 
					onComplete<span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">this</span>.signalIntroComplete 
				<span style="color: #000000;">&#125;</span> 
			<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> action<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> ct<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">ColorTransform</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ColorTransform</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			ct.<span style="color: #004993;">color</span> = 0x0000FF;
&nbsp;
			FSMTest<span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span>.context <span style="color: #000000;">&#41;</span>.square.<span style="color: #004993;">transform</span>.<span style="color: #004993;">colorTransform</span> = ct;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Now lets add it the the StateManager.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">_manager = <span style="color: #0033ff; font-weight: bold;">new</span> StateManager<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span>;
_manager.addState<span style="color: #000000;">&#40;</span> InitState.KEY, <span style="color: #0033ff; font-weight: bold;">new</span> InitState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span>;
_manager.addState<span style="color: #000000;">&#40;</span> BlueState.KEY, <span style="color: #0033ff; font-weight: bold;">new</span> BlueState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Run the example and you&#8217;ll see that our square immediatly goes to the Initial state and turns red.  That the basics of it, pretty easy right.</p>
<p>So now, lets change states.  We&#8217;ll do this by making square a button and when clicked will move our square to the &#8216;BlueState&#8217;.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">square.<span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
square.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, changetoBlueState <span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Now lets create the &#8220;changeToBlueSate&#8221; function and call the &#8220;setState&#8221; method on our StateManager.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> changeToBlueSate<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	_manager.setState<span style="color: #000000;">&#40;</span> BlueState.KEY <span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Run the code again, and then click on our new button.  So far so good.  Let&#8217;s now make away to go back to the InitState when we get to BlueState.  The StateManager dispatches events at all parts of a state change.  They are &#8220;onIntroStart&#8221;, &#8220;onIntroComplete&#8221;, &#8220;onAction&#8221;, &#8220;onOutroStart&#8221;, and &#8220;onOutroComplete&#8221;.  The event fired has reference to State key.  We&#8217;ll use this to remove the current listener to move to blue and replace it with one to move to Init.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">_manager.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> StateManagerEvent.ON_OUTRO_START, onOutroStart <span style="color: #000000;">&#41;</span>;
_manager.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> StateManagerEvent.ON_INTRO_START, onIntroStart <span style="color: #000000;">&#41;</span>;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onOutroStart<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span>StateManagerEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">switch</span><span style="color: #000000;">&#40;</span>e.key<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">case</span> InitState.KEY<span style="color: #000000; font-weight: bold;">:</span>
			square.<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, changeToBlueSate <span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">break</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onIntroStart<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span>StateManagerEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">switch</span><span style="color: #000000;">&#40;</span>e.key<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">case</span> BlueState.KEY<span style="color: #000000; font-weight: bold;">:</span>
			square.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, changeToInitState <span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">break</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Run the code again and play with it.</p>
<p><strong>ADDING SOME POLISH</strong></p>
<p>I&#8217;ve included some helper class you can extend if you&#8217;re going to be using Movieclips or Sprites.  They initialize the StageManger and even listen for all the different events that get fired. Just override some protected function in order to add and remove event listeners based on the state you&#8217;re in.</p>
<p><strong>WHAT NOW?</strong></p>
<p>The possiblities our endless.  For games, you can use this for character animations.  You don&#8217;t have to use tweens, you can control frames in your states using the Movieclip methods.  I&#8217;ve built really neat looking menus and the animation of pages loading in an out. I love this library and hope that you&#8217;ll love it too. It&#8217;s really up to you how you want to use it.</p>
<p><a href="https://github.com/meekgeek/Meek-FSM">Download the code here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://meekgeek.com/actionscript/as3-finite-state-machine/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Delicious Bookmarks Alternative</title>
		<link>http://meekgeek.com/development/delicious-bookmarks-alternative/</link>
		<comments>http://meekgeek.com/development/delicious-bookmarks-alternative/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 15:53:02 +0000</pubDate>
		<dc:creator>Joel Caballero</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://meekgeek.com/?p=226</guid>
		<description><![CDATA[I was very disappointed to hear the rumors yesterday that delicious bookmarks were to be no more. I don&#8217;t know what this really mean for Delicious and all of it&#8217;s users exactly. I would think that there&#8217;s still some money to be made from this site. Anyway, rather than wait to see the day when [...]]]></description>
			<content:encoded><![CDATA[<p>I was very disappointed to hear the rumors yesterday that delicious bookmarks were to be no more.   I don&#8217;t know what this really mean for Delicious and all of it&#8217;s users exactly.  I would think that there&#8217;s still some money to be made from this site.  Anyway, rather than wait to see the day when I can&#8217;t save my book marks, I thought I would take the time to find an alternative.  </p>
<p>My criteria for finding my next bookmarking tool were as follows:</p>
<ul>
<li>Was it free? I don&#8217;t like spending my money</li>
<li>Was it cluttered? I hate seeing ads everywhere</li>
<li>Nice user interface</li>
<li>How mobile is it? I want to make sure I have them everywhere I go</li>
</ul>
<p>  I narrowed my search to a hand full of alternatives.  The following is a list of other services I considered with reasons why I decided not to commit.</p>
<ul>
<li><strong>Google Bookmarks</strong><br />
This probably would have been my first choice but my Gmail account tied to my Google account is messed up and Google provides no way to change it. It&#8217;s really been a soar spot for me when it comes to Google services in general.  Plus, I would have to install some bulky toolbar in Firefox.  Sorry Google, I just need a little bit of space.</li>
<li><strong>Pinboard.in</strong><br />
Almost jumped on board with this, It was $8.10 when I wrote this.  The pressure was killing me, and I&#8217;ve learned to never do things under pressure.  Plus if you look at the fine print, some of the services coast $25 dollars a year.</li>
<li><strong>Zootool</strong><br />
They don&#8217;t even work right now.  The rumors where too much for there servers to handle.  Say&#8217;s a lot about a the people who run it too me.  Won&#8217;t even bother.</li>
<li><strong>Diigo</strong><br />
They have an impressive set of features but I didn&#8217;t like the clutter. It can get kinda pricey too.</li>
</ul>
<p><strong>AND THE WINNER IS</strong><br />
After a couple of hours of research, I bookmarked what might be my last bookmark on delicious.  I&#8217;ve settled on <a href="http://www.xmarks.com/">Xmarks</a>.  Why, there&#8217;s no clutter.  There&#8217;s no ads that I can see right away and if I want to upgrade, the cost is minimal.  The tools fit nicely in the browser and are available for all the browsers I use.  In the end, I feel good about my purchase because I haven&#8217;t spent any money yet.  </p>
<p>Hope this helps somebody make a decision. </p>
<p><strong>[UPDATE]</strong></p>
<p>After only a few hours my Firefox bookmark database got corrupt.  I&#8217;m not blaming Xmarks, but in desperation I quickly opened a Pinboard account for $8.31.</p>
<p><strong>[UPDATE]</strong></p>
<p>Delicious isn&#8217;t going anywhere, it&#8217;s the best out there so I probably won&#8217;t be going anywhere.  You can check out there blog <a href="http://blog.delicious.com/">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://meekgeek.com/development/delicious-bookmarks-alternative/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IPad Review: Kindle vs iPad vs MacBook</title>
		<link>http://meekgeek.com/apple/ipad-review-kindle-vs-ipad-vs-macbook/</link>
		<comments>http://meekgeek.com/apple/ipad-review-kindle-vs-ipad-vs-macbook/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 23:59:11 +0000</pubDate>
		<dc:creator>Joel Caballero</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[IPad]]></category>

		<guid isPermaLink="false">http://meekgeek.com/?p=203</guid>
		<description><![CDATA[This is obviously going to be a completely biased review of the new IPad since I sold my Kindle to buy it, but I couldn&#8217;t help myself see how many more hits I get by titling it the way I did. Today I woke up excited to get to the Apple store and purchase the [...]]]></description>
			<content:encoded><![CDATA[<p>This is obviously going to be a completely biased review of the new IPad since I sold my Kindle to buy it, but I couldn&#8217;t help myself see how many more hits I get by titling it the way I did.</p>
<p>Today I woke up excited to get to the Apple store and purchase the new IPad.  I stood in line for about 30 minutes while my turn came up, when it finally did, the worker was very attentive and almost made me believe the apple care plan was worth it.  She asked me if I&#8217;d had a chance to try it out.  When I said, &#8220;It&#8217;s just a big IPhone, isn&#8217;t it?&#8221; she acted if I kicker her in the face.  She was like, &#8220;No! don&#8217;t say that! It&#8217;s way more.&#8221;  I&#8217;d later realize that she was kind of right.</p>
<p>I came home and plugged it into my MacBook Pro.  ITunes alerted me that I needed to update to the latest version. About one hour later, I was finally up and running.  It seems you can&#8217;t even start it up to the home screen unless you go through this step.  The first thing you&#8217;ll want to do when you start it is sync it up to your ITunes.  You&#8217;ll see a screen that asks you if you want to use your IPhone&#8217;s data to sync it up or start it up as new.  I selected &#8220;start up as new&#8221; and I suggest you do the same because I was surprised to see that all of your IPhone application don&#8217;t work the way you would expect on your IPad.  Apps made for your IPhone will display at the same resolution on your IPad, which means you&#8217;ll see a lot of black surrounding your little app in the middle &#8211; not good.  This means that you&#8217;ll start looking for IPad versions of the same app as soon as you see how nasty it looks when you try and scale it up.  Another thing that you might notice is that the apps are a little more expensive.  I believe companies think if your buying apps this early in the IPad game, you have a little money to spend, whatever, they&#8217;re probably right, and I&#8217;ve spent $25 dollars in apps today to prove it.</p>
<p>When you&#8217;re done syncing, you&#8217;ll want to start playing with it, but wait! You&#8217;ll need to get your Wi-Fi password to get your IPad working to it&#8217;s full potential.  This part really frustrated me, connecting to my network was not cut and dry.  It took several attempts.  I realize that everyone&#8217;s network is different but I would be curious to see if I&#8217;m not the only one to have these troubles.  However, now that I&#8217;ve got it successfully set up, my IPhone hasn&#8217;t been able to connect. Perhaps I&#8217;ve exceeded my wireless connections?</p>
<p>So once I was on, my next stop was the apple store.  One of the first apps you&#8217;ll see in the featured section is IWorks.  I believe it&#8217;s a group of apps that contains a word processor (Pages) and some other apps that allow you to prepare presentations.  I don&#8217;t believe the IPad will replace your computer for things like this.  I suggest you restrain from buying these types of apps until you get a little more familiar with the key board. Like I said before, be prepared to pay a little more of some of your favorite apps.</p>
<p>I&#8217;ve had a chance to play with my new toy for a few hours now and I&#8217;m liking what I see.  Is it worth the money? I think so.  You see, there are certain apps that I believe are better served from this screen.  Will it replace your IPhone? I think not, although that thought did cross my mind.  Like I said before, most of the apps I use are better served on this new resolution.  Will it replace the computer?  Definitely not! Or at least, definitely not right now!</p>
<p><strong>VS KINDLE</strong></p>
<p>IPad wins hands down.  My new IPad is years ahead of the Kindle, and no one can argue with that.  I almost felt bad for the poor girl who ended up buying my old kindle, but I&#8217;m glad she did.  Apple put out a Kindle reader and that pretty much put the nail in the coffin. Now to tell you the truth, I only bought one Kindle book. The main reason why I bought these two products was for their PDF support. Kindle allowed me to view them, but it&#8217;s lack of the zoom feature really bugged me sometimes. Especially when the PDF resolution wasn&#8217;t as great as I would have wanted.  The native PDF support on the IPad doesn&#8217;t allow me to save my spot but I was able to find an app that did. </p>
<p> <strong>VS MACBOOK</strong></p>
<p>The real question is, will this ( I say &#8220;this&#8221; because I&#8217;m actually writing this part of the post on it. ) IPad revolutionize the way we compute, like Steve Jobs said it would?  I&#8217;m afraid to say this, but it just might.  My first thought was that there was no way to replace the key board.  I mean, we need to feel the keys if we wanted to really get rid of it, but I&#8217;m very surprised at how fast I&#8217;ve been able get through this.  It is something you have to get use to. </p>
<p>That being said, my MacBook Pro has now become obsolete for a lot of what I&#8217;ve used it for in the past. Come to think about it, my Iphone has become obsolete for somethings as well. But the fact of the matter is, developers like me need a mouse and it will take a long time for it to be replaced by all eight fingers. Obviously, the computing power of an IPad is about a fraction of what my laptop can do but my grandma could care less, and really, it&#8217;s the consumer who uses the computer for casual things like email that really benefit from products like this. </p>
<p><strong>THE CONCLUSION</strong></p>
<p>This is a developers blog and the IPad is my tool.  I&#8217;d like to leave you with a few apps that are essential to somebody like me.</p>
<ul>
<li><a href="http://itunes.apple.com/us/app/wordpress/id335703880?mt=8">WordPress for IPad</a></li>
<li><a href="http://itunes.apple.com/us/app/pdf-reader-pro-edition-for/id364502063?mt=8">PDF Reader Pro for IPad</a></li>
<li><a href="http://itunes.apple.com/us/app/netnewswire-for-ipad/id363704172?mt=8">NetNewWire</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://meekgeek.com/apple/ipad-review-kindle-vs-ipad-vs-macbook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Serializing in Coldfusion</title>
		<link>http://meekgeek.com/coldfusion/serializing-in-coldfusion/</link>
		<comments>http://meekgeek.com/coldfusion/serializing-in-coldfusion/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 02:26:54 +0000</pubDate>
		<dc:creator>Joel Caballero</dc:creator>
				<category><![CDATA[Coldfusion]]></category>

		<guid isPermaLink="false">http://meekgeek.com/?p=164</guid>
		<description><![CDATA[In one of my more recent projects, it became necessary to store an array for later use. Mysql does not support this feature. However, it is possible to store binary data and a Mysql Blob is the perfect data type for just this. In fact you can store just about anything you want with this [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my more recent projects, it became necessary to store an array for later use.  Mysql does not support this feature. However, it is possible to store binary data and a <a href="http://dev.mysql.com/doc/refman/5.0/en/blob.html">Mysql Blob</a> is the perfect data type for just this.  In fact you can store just about anything you want with this method, whether it be an image, pdf, or even a Coldfusion component, these two little function will serve you great.   </p>
<p><strong>A LITTLE JAVA TO THE RESCUE</strong></p>
<p>The code below has been posted on several blogs.  I&#8217;ve found versions of it at <a href="http://www.petefreitag.com/item/649.cfm">Pete Freitag&#8217;s</a> site.  I modified it just a tad to serve my purpose.  Now it&#8217;s object in, binary out and vice versa.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;serialize&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Binary&quot;</span> <span style="color: #0000FF;">&gt;</span></span>
     <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;object&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;any&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
	   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> byteOut <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;java.io.ByteArrayOutputStream&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
	   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> byteOut.init<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
	   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> objOut <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;java.io.ObjectOutputStream&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
	   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> objOut.init<span style="color: #0000FF;">&#40;</span>byteOut<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
	   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> objOut.writeObject<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">object</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> objOut.close<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
     <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> byteOut.toByteArray<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;deserialize&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;any&quot;</span><span style="color: #0000FF;">&gt;</span></span>
     <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;data&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Binary&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
          <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> inputStream <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;java.io.ByteArrayInputStream&quot;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> objIn <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;java.io.ObjectInputStream&quot;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #0000FF;">object</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
	  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> inputStream.init<span style="color: #0000FF;">&#40;</span> <span style="color: #0000FF;">data</span> <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
          <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> objIn.init<span style="color: #0000FF;">&#40;</span>inputStream<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #0000FF;">object</span> <span style="color: #0000FF;">=</span> objIn.readObject<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
	  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> objIn.close<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
     <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> <span style="color: #0000FF;">object</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p><strong>AND NOW FOR A REAL EXAMPLE</strong></p>
<p>The following code invokes a Serializer component, then creates a struct, and puts some code in it.  I call a stored procedure that excepts my serialized struct.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfinvoke</span> component<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;com.meekgeek.utils.Serializer&quot;</span> <span style="color: #0000FF;">method</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;init&quot;</span> returnvariable<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;serializer&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> myStruct <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">structNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> myStruct<span style="color: #0000FF;">&#91;</span><span style="color: #009900;">&quot;SomeNumber&quot;</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #FF0000;">1</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> myStruct<span style="color: #0000FF;">&#91;</span><span style="color: #009900;">&quot;MyArray&quot;</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">ArrayNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> results <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfstoredproc</span> <span style="color: #0000FF;">datasource</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#APPLICATION.dataSource#&quot;</span> procedure<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;save_struct_stored_procedure&quot;</span><span style="color: #0000FF;">&gt;</span></span>
   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfprocparam</span> cfsqltype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;CF_SQL_BLOB&quot;</span> variable<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;_MY_STRUCT&quot;</span> <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#serializer.serialize(myStruct)#&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfprocresult</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;results&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfstoredproc</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Now, I will retrieve my struct and dump it.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfinvoke</span> component<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;com.meekgeek.utils.Serializer&quot;</span> <span style="color: #0000FF;">method</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;init&quot;</span> returnvariable<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;serializer&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> results <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfstoredproc</span> <span style="color: #0000FF;">datasource</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#APPLICATION.dataSource#&quot;</span> procedure<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;get_struct_stored_procedure&quot;</span><span style="color: #0000FF;">&gt;</span></span>
   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfprocresult</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;results&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfstoredproc</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> unserialized <span style="color: #0000FF;">=</span> serializer.deserialize<span style="color: #0000FF;">&#40;</span> results.My_Struct <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfdump</span> <span style="color: #000000; font-weight: bold;">var</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#unserialized#&quot;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>Now, before you go about serializing everything.  There are a few things you should know.  Morgan Tocker posted an article you should read titled <a href="http://www.mysqlperformanceblog.com/2010/01/21/when-should-you-store-serialized-objects-in-the-database/">When should you store serialized objects in the database?</a>  I hope this saves someone some time.</p>
<p>You can download the class above <a href="http://meekgeek.com/100121/src/Serializer.cfc.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://meekgeek.com/coldfusion/serializing-in-coldfusion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rackspace Cloud Servers &#8211; Here I Come</title>
		<link>http://meekgeek.com/linux/rackspace-cloud-servers-here-i-come/</link>
		<comments>http://meekgeek.com/linux/rackspace-cloud-servers-here-i-come/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 19:56:58 +0000</pubDate>
		<dc:creator>Joel Caballero</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://meekgeek.com/?p=121</guid>
		<description><![CDATA[WHERE HAVE YOU BEEN ALL MY LIFE! I&#8217;m not sure how long they&#8217;ve been providing this service but I do know I&#8217;ve been missing out. Say good bye to limits imposed by your current hosting providers. Rackspace offers a virtually dedicated server of your own for probably less than what your spending right now. Choose [...]]]></description>
			<content:encoded><![CDATA[<p><strong>WHERE HAVE YOU BEEN ALL MY LIFE!</strong></p>
<p>I&#8217;m not sure how long they&#8217;ve been providing this service but I do know I&#8217;ve been missing out. Say good bye to limits imposed by your current hosting providers. Rackspace offers a virtually dedicated server of your own for probably less than what your spending right now.  Choose a server size and pay for what you use. They offer root access and it&#8217;s fully customizable.</p>
<p><strong>HOW IT WORKS</strong></p>
<p>You select the size of your server.  Anything from 256 up to 16 GB, then you select your operating system.  If you&#8217;re a more experience Linux user and love the technical stuff  you will consider going with Fedora, or if you&#8217;re more of a beginner (like me) and need a community you won&#8217;t be afraid to ask question in, you&#8217;d select something like Ubuntu. Then you can start playing with it.  They provide you with a graphical shell you can use to start plugin away, start up terminal (on a mac), or download <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">Putty</a> on windows.</p>
<p><strong>WHY I&#8217;M MOVING</strong></p>
<p>It&#8217;s complicated really, my main reason for going with <a href="http://gearhost.com">Gearhost</a> in the first place was because they provide great Coldfusion service for a very low price.  Well, after the last Adobe Max conference I went to, I realized just how expensive programming for Adobe can be, and Enterprise level solutions are starting to be something I&#8217;m interested in.  Coldfusion Enterprise is something out of my price range, and <a href="http://www.adobe.com/products/livecycle/">LiveCycle ES2</a> is something not even our clients can afford.  I don&#8217;t think I&#8217;m the only one who feels this way.  So I&#8217;ve decided to learn JAVA and hope that Adobe provides a free Coldfusion solution in the near future.</p>
<p>Don&#8217;t get me wrong, if your looking for great Coldfusion hosting, check out <a href="http://gearhost.com">Gearhost</a>.  I don&#8217;t think you&#8217;ll be disappointed.</p>
<p><strong>WANT TO FOLLOW ME?</strong></p>
<p>You&#8217;ll have to know some Linux, and well, just about 3 weeks ago, I didn&#8217;t know it either.  <a href="http://www.amazon.com/Beginning-Ubuntu-Server-Administration-Professional/dp/1590599233/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1261544568&#038;sr=8-1">Beginning Ubuntu Server Administration: From Novice to Professional</a> was a great book to help me get started.  But here&#8217;s a few commands to help you get started&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#Change Directory</span>
root<span style="color: #000000; font-weight: bold;">@</span>yourserver:~<span style="color: #666666; font-style: italic;"># cd /directory</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#See Files and Folers in Current Directory</span>
root<span style="color: #000000; font-weight: bold;">@</span>yourserver:~<span style="color: #666666; font-style: italic;"># ls</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#View File Conents</span>
root<span style="color: #000000; font-weight: bold;">@</span>yourserver:~<span style="color: #666666; font-style: italic;"># cat yourfile</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Edit A File</span>
root<span style="color: #000000; font-weight: bold;">@</span>yourserver:~<span style="color: #666666; font-style: italic;"># vim yourfile</span>
<span style="color: #666666; font-style: italic;">#To quit the editor hit escape, then, type ':wq!' without quotes to save it, </span>
<span style="color: #666666; font-style: italic;">#or type ':q!' to quite without saving.  </span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Create A File</span>
root<span style="color: #000000; font-weight: bold;">@</span>yourserver:~<span style="color: #666666; font-style: italic;"># touch filename</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Removes File</span>
root<span style="color: #000000; font-weight: bold;">@</span>yourserver:~<span style="color: #666666; font-style: italic;"># rm yourfile</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Create a Directory</span>
root<span style="color: #000000; font-weight: bold;">@</span>yourserver:~<span style="color: #666666; font-style: italic;"># mkdir directory</span></pre></div></div>

<p>You don&#8217;t have to type in the &#8220;root@yourserver:~#&#8221; part.  &#8216;root&#8217; is the user your logged in as and &#8216;yourserver&#8217; is your server.  I hope this helps someone.  And if anybody wants, I could post a detailed explanation on how to set up your new server for wordpress.</p>
]]></content:encoded>
			<wfw:commentRss>http://meekgeek.com/linux/rackspace-cloud-servers-here-i-come/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving time with JSFL</title>
		<link>http://meekgeek.com/actionscript/saving-time-with-jsfl/</link>
		<comments>http://meekgeek.com/actionscript/saving-time-with-jsfl/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 13:58:30 +0000</pubDate>
		<dc:creator>Joel Caballero</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[JSFL]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://meekgeek.com/?p=104</guid>
		<description><![CDATA[If you haven't already figured out the beauty of JSFL, your in for a treat.  With JSFL you can control virtually every part of the flash IDE.  You can say good-bye to the mundane tasks that you sometimes find yourself doing in flash.  This isn't a tutorial on how to use it, it's just a demonstration on what you can use it on.  Plus two free scripts that you can modify or just use in your next project.]]></description>
			<content:encoded><![CDATA[<p>A co-worker of mine needed to go through a thousand or so instances on stage and name them according to there respective Class names.  This could take a few hours of copying, pasting, then renaming.  This could easily lead to a nervous melt down if your not careful.</p>
<p><strong>JSFL FILE TO THE RESCUE</strong>  </p>
<p>JSFL stands for JavaScript Flash. A JSFL file contains a form of JavaScript that the Flash IDE uses to automate task.  Almost anything that you do in flash, you can do with JSFL.  Let&#8217;s say for example you wanted to add a new scene.  The code would look something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">flash.getDocumentDOM<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.addNewScene<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;myScene&quot;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>You can see all that JSFL has to offer by downloading the documentation <a href="http://livedocs.adobe.com/flash/9.0/main/flash_cs3_extending.pdf ">here</a>. </p>
<p><strong>SOME FREE STUFF!</strong></p>
<p>So remember my co-worker?  I coded a simple script that allows you to select all the instances on the stage and name them all according to there class names.  I also created one that allowed you to select an instance that had a shape in it and convert it into a MovieClip.  He was then able to link these scripts to a quick key and finish the job in a fraction of the time.</p>
<p>You can download the source code <a href="http://meekgeek.com/090820/src/jsfl.zip">here</a>.  Feel free to use it and modify it.</p>
]]></content:encoded>
			<wfw:commentRss>http://meekgeek.com/actionscript/saving-time-with-jsfl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flash Remoting with NetConnection for Intermediates</title>
		<link>http://meekgeek.com/actionscript/flash-remoting-with-netconnection-for-intermediates/</link>
		<comments>http://meekgeek.com/actionscript/flash-remoting-with-netconnection-for-intermediates/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 07:18:44 +0000</pubDate>
		<dc:creator>Joel Caballero</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Flash Remoting]]></category>
		<category><![CDATA[Coldfusion]]></category>

		<guid isPermaLink="false">http://meekgeek.com/?p=77</guid>
		<description><![CDATA[In my <a href="http://meekgeek.com/index.php/archives/24">first article</a> I introduced you to to Flash Remoting. In the second part of this three series article on Flash Remoting I'd like to introduce users to a few libraries out there right now that help a great deal when using Remoting.  I'll also let you know what to watch out for and the "Gotchas" that you might encounter.  I'll finally introduce you to Value Objects and why your going to want to use them.  ]]></description>
			<content:encoded><![CDATA[<p>The days of easy Flash Remoting for us pure ActionScript 3 ( Not Flex ) programmers are over.  No more being pampered by Adobe with cool NetConnection Debuggers and &#8220;easy&#8221; to use components.  If you do a search for &#8220;Flash Remoting&#8221; on google you&#8217;ll find a link to an out of date product at Adobe.  I&#8217;m not sure why they still sell it.  I&#8217;m assuming it&#8217;s adobe&#8217;s way to show support for .NET.</p>
<p><strong>WHAT IS THERE NOW?</strong></p>
<p>We don&#8217;t have the Service class of ActionScript 2.0 anymore so what do we do?  You can feel good in knowing that many programmers have already taken the time to create great libraries for remoting.  Here&#8217;s a few different libraries to get you started.</p>
<ul>
<li><a href="http://www.bytearray.org/?p=122">ByteArray.org</a> By: Thibault Imbert</li>
<li><a href="http://blog.foxrocklive.com/flash-cs3-cs4-actionscript-remoting-libraries/">Foxrock</a> By: Epox</li>
<li><a href="http://as3lrf.riaforge.org/">As3lrf</a> By: Danny Patterson</li>
</ul>
<p>There are many others out there but these are the ones that I&#8217;ve used personally and recommend.  </p>
<p><strong>THINGS YOU MAY INCOUNTER</strong></p>
<p>The first thing you&#8217;ll want to watch out for is <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/ObjectEncoding.html">ObjectEncoding</a>.  This property indicates which Action Message Format (AMF) the player is using to serialize the data.  There are two version of AMF, AMF3 and AMF0.  There are many advantages in using AMF3 and you can read all about them in the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/index.html">ActionScript3 Language Reference</a>.  By default the NetConnection class uses AMF3, this is great except that sometimes you might need to change this to AMF0 in order for your data to serialize correctly.  That being said, after reading this post and my upcoming post on Flash Remoting with AMF3 ( Not Flex ) and Coldfusion, you&#8217;ll never need to use anything other than AMF3.</p>
<p>The second thing you might encounter might be when returning a struct from Coldfusion  to flash.  There has been some issues with your result properties coming back in uppercase.  Leif Wells wrote a little about this on his blog <a href="http://www.leifwells.com/index.cfm/2007/11/8/ColdFusion-to-Flex-Remoting-UPPERCASE-Rage">here</a>.  To be honest, this has not been a problem for me because anything I can put in a struct I can put in a Value Object and this is what we&#8217;ll talk about next.</p>
<p>Also note, if you&#8217;re application will be needing to authenticate a user you&#8217;ll want to look into the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/NetConnection.html#addHeader()">addHeader</a> method of the NetConnection class.  It will do the trick.</p>
<p><strong>VALUE OBJECTS</strong></p>
<p>Value Objects are probably one of the top 5 reasons to use Remoting in the first place.  They&#8217;re simply an object of properties you want to send to your Application Server.  The player registers and links them to an object on the application server. These Value Objects are then serialized and converted correctly for everyone to enjoy.  This conversion also works when sending data back to flash.  </p>
<p>The trick to getting these objects converting correctly lies in the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/package.html#registerClassAlias()">registerClassAlias</a> method.  It accepts two parameters, the first is a string that represents the server side component, and the second is the ActionScript class you&#8217;ll be linking it with.  Make sure you register your class before you try using it.  Using Epox&#8217;s <a href="http://blog.foxrocklive.com/flash-cs3-cs4-actionscript-remoting-libraries/">remoting library</a> provides a neat method for doing this.  Patrick Tai wrote a very nice tutorial on Value Objects titled <a href="http://mxbase.blogspot.com/2008/07/passing-custom-objects-between-flex-and.html">Passing custom objects between Flex and CF</a>.  It&#8217;s probably the best tutorial I&#8217;ve seen expect it&#8217;s assuming your only using Flex.</p>
<p><strong>IN CONCLUSION</strong></p>
<p>You&#8217;ll have a lot of fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://meekgeek.com/actionscript/flash-remoting-with-netconnection-for-intermediates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Remoting with NetConnection for Beginners.</title>
		<link>http://meekgeek.com/actionscript/flash-remoting-with-netconnection-for-beginners/</link>
		<comments>http://meekgeek.com/actionscript/flash-remoting-with-netconnection-for-beginners/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 19:21:28 +0000</pubDate>
		<dc:creator>Joel Caballero</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Flash Remoting]]></category>
		<category><![CDATA[Coldfusion]]></category>

		<guid isPermaLink="false">http://meekgeek.com/?p=24</guid>
		<description><![CDATA[In the first part of this three series article of Flash Remoting I'll try an introduce beginners into the joys of Remoting with flash.  I'll first explain briefly what it is and what the benefits are over other traditional methods of data handling.  I'll then introduce you to the tools you'll need to get started.  I'll finally explain the 'NetConnection' class and how to successfully connect to a gateway and start sending data back and forth.]]></description>
			<content:encoded><![CDATA[<p><strong>WHAT IS IT?</strong></p>
<p>Flash Remoting is just the way in which your ActionScript project connects to an application server like Coldfusion or PHP.  It allows you to receive request by passing parameters through this connection.  Very simply, it allows you to use your server side methods like an extension of your ActionScript.  The end result is a Rich Internet Application that was both quick and easy to put together.</p>
<p><strong>WHAT ARE THE BENEFITS?</strong></p>
<p>The benefits of remoting might not be very apparent at first.  Some might think that you can do anything you need via XML and the URLLoader class via &#8220;POST&#8221; and &#8220;GET&#8221; methods.  You could do that; you could also get from L.A to New York on a tricycle.  This method works, but what your effectively making is a middle man between your application and your data.  You don&#8217;t need him, he&#8217;s just there to make your life a little harder.  When compared to Remoting, this method is just not as efficient.</p>
<p>Lets take for example a small project where you want update a users phone number.  The user presses the update button, your application starts packaging up the data in a well formed XML structure.  The XML gets sent to your application server where it starts to drill down to the phone data you sent.  It then updates your database and sends back some kind of name value pair that informs you wether or not the transaction was successful.  I know that you didn&#8217;t really need a XML file to send this data.  A name value pair would have been enough, but I&#8217;m trying to illustrate a point here.  The point being that you had to parse the data on both the application server and then back when you receive a response.  What if you wanted to pass a list of phone numbers in an array.  Oh wait, you can&#8217;t send arrays via that method, only strings, looks like your going to have to package that up too.</p>
<p>Remoting solves scenarios like this.  It not only handles all datatype conversion between your ActionScript and your application server.  Under the hood, it serializes your data and sends it out in a more fast efficient way, improving your applications performance. And like in the example above, your application can get complex, wouldn&#8217;t it be nice to have a more consistent API for calling your server-side methods?</p>
<p><strong>OK, I&#8217;M SOLD, WHAT DO I NEED?</strong></p>
<p>The good news is that if your application server is Coldfusion, you don&#8217;t need anything.  If your coding with PHP you can use <a href="http://www.amfphp.org/">AMFPHP</a>.  These are the only two that I&#8217;ve used and have personally worked with but Remoting is supported on all major servers.  A search for &#8220;Flash Remoting for <em>your server here</em>&#8221; will give you the results that you want.  If your a Java Developer, check out <a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/">BlazeDS</a>.  There are many open-sourced solutions out there so money shouldn&#8217;t be a problem.</p>
<p><strong>LETS DO THIS!</strong></p>
<p>The following is the file structure that is used for this example.  It consist of two files, the SWF and the CFC.  The CFC is placed inside a &#8216;components&#8217; folder.  </p>
<div>
<img src="http://meekgeek.com/090403/images/structure.png" alt="root structure" />
</div>
<p>The autonomy of a NetConnection call is very simple.  You can see all of the of NetConnection&#8217;s methods <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/NetConnection.html">here</a>.   The only two methods we&#8217;ll need is &#8220;connect&#8221; and &#8220;call&#8221;. The following code sends the string &#8220;Flash&#8221; to a method &#8220;hello&#8221; in a &#8220;service&#8221; cfc file, located in a &#8220;components&#8221; folder on the root directory.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">NetConnection</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #004993;">Responder</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> FlashRemoting extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> gateway<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;http://{your domain}/flashservices/gateway&quot;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> service<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;components.service&quot;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">method</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>  = <span style="color: #990000;">&quot;.hello&quot;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> nc<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">NetConnection</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> responder<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Responder</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> FlashRemoting<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span>.nc = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">NetConnection</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">this</span>.nc.<span style="color: #004993;">connect</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span>.gateway <span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">this</span>.responder = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Responder</span><span style="color: #000000;">&#40;</span> onResult, onFault <span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">this</span>.nc.<span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">this</span>.service<span style="color: #000000; font-weight: bold;">+</span><span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">method</span>, <span style="color: #0033ff; font-weight: bold;">this</span>.responder, <span style="color: #990000;">&quot;Flash&quot;</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onResult<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> e <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onFault<span style="color: #000000;">&#40;</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> e <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Before you can make a call to your application server, you have to set up the connection.  Please note, when you call connection, it doesn&#8217;t actually check weather or not your connection will work.  NetConnection just keeps that URI referenced for when you use the call method.  The call method accepts an indefinite number of arguments, the first is a reference to the method your trying to call, it&#8217;s preceded by the service.  You could  of just placed this string for the first parameter &#8211; &#8220;components.service.hello&#8221;. The second is a Responder class, which is nothing more than a reference to a function to call if you get a result and one if something wrong happens.  From there on, you can pass as many parameters you want to pass to your method.</p>
<p>It&#8217;s that simple.  Running this example will return a string like this, &#8220;Hello Flash, I&#8217;m Coldfusion&#8221;.</p>
<p>You can dowload the source for this exmple <a href="http://meekgeek.com/090403/source/src.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://meekgeek.com/actionscript/flash-remoting-with-netconnection-for-beginners/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

