<?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>Pragmatic Flex</title>
	<atom:link href="http://PragmaticFlex.com/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://PragmaticFlex.com/blog</link>
	<description>Real world knowledge for the Flash Platform</description>
	<lastBuildDate>Tue, 08 Dec 2009 14:12:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Formatting And Sorting Dates In DataGrid</title>
		<link>http://PragmaticFlex.com/blog/posts/458</link>
		<comments>http://PragmaticFlex.com/blog/posts/458#comments</comments>
		<pubDate>Tue, 08 Dec 2009 14:12:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[formatter]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://PragmaticFlex.com/blog/?p=458</guid>
		<description><![CDATA[So you’ve got a DataGrid and you want to format the dates and sort the dates regardless of how  its formatted. It’s pretty straight forward using the labelFunction and  sortCompareFunction on the DataGridColumn.]]></description>
			<content:encoded><![CDATA[<p>So you’ve got a DataGrid and you want to format the dates and sort the dates regardless of how  its formatted. It’s pretty straight forward using the labelFunction and  sortCompareFunction on the DataGridColumn.</p>
<p>First we’ll set up the data and datagrid.</p>
<pre class="brush: as3;">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
 xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
 xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot; minWidth=&quot;1024&quot; minHeight=&quot;768&quot;&gt;
 &lt;fx:Declarations&gt;
 &lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt;

 &lt;/fx:Declarations&gt;
 &lt;fx:Script&gt;
 &lt;![CDATA[
 import mx.collections.ArrayCollection;

 [Bindable]
 private var initDG:ArrayCollection = new ArrayCollection([
				{ID:1, datePosted:&quot;03/15/2009&quot;},
				{ID:2, datePosted:&quot;02/18/2009&quot;}
 ]);

 ]]&gt;
 &lt;/fx:Script&gt;

 &lt;mx:DataGrid dataProvider=&quot;{initDG}&quot; id=&quot;dg0&quot; x=&quot;0&quot; y=&quot;0&quot; width=&quot;100%&quot; height=&quot;100%&quot;&gt;
 &lt;mx:columns&gt;
 &lt;mx:DataGridColumn headerText=&quot;ID&quot; dataField=&quot;ID&quot; width=&quot;25&quot; /&gt;
 &lt;mx:DataGridColumn headerText=&quot;Date&quot; dataField=&quot;datePosted&quot; /&gt;
 &lt;/mx:columns&gt;
 &lt;/mx:DataGrid&gt;
&lt;/s:Application&gt;
</pre>
<p>Now lets add the date formatter. Add the date formatter component and identify the resulting format you&#8217;re looking for. Next we add a function that uses that date formatter.<br />
Finally we&#8217;ll add a call to our function from the datagrid column using labelFunction</p>
<pre class="brush: as3;">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
 xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
 xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot; minWidth=&quot;1024&quot; minHeight=&quot;768&quot;&gt;
 &lt;fx:Declarations&gt;
 &lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt;
 &lt;mx:DateFormatter id=&quot;dateFormatter&quot; formatString=&quot;MMMM D, YYYY&quot; /&gt;

 &lt;/fx:Declarations&gt;
 &lt;fx:Script&gt;
 &lt;![CDATA[
 import mx.collections.ArrayCollection;

 [Bindable]
 private var initDG:ArrayCollection = new ArrayCollection([
				{ID:1, datePosted:&quot;03/15/2009&quot;},
				{ID:2, datePosted:&quot;02/18/2009&quot;}
 ]);

 private function dateFormat(item:Object, eventGridColumn:DataGridColumn):String
 {
 return dateFormatter.format(item.datePosted);
 }

 ]]&gt;
 &lt;/fx:Script&gt;

 &lt;mx:DataGrid dataProvider=&quot;{initDG}&quot; id=&quot;dg0&quot; x=&quot;0&quot; y=&quot;0&quot; width=&quot;100%&quot; height=&quot;100%&quot;&gt;
 &lt;mx:columns&gt;
 &lt;mx:DataGridColumn headerText=&quot;ID&quot; dataField=&quot;ID&quot; width=&quot;25&quot; /&gt;
 &lt;mx:DataGridColumn headerText=&quot;Date&quot; dataField=&quot;datePosted&quot; labelFunction=&quot;dateFormat&quot;/&gt;
 &lt;/mx:columns&gt;
 &lt;/mx:DataGrid&gt;
&lt;/s:Application&gt;
</pre>
<p>To add the sorting we&#8217;ll add a sorting method and call it from our datagrid column using sortCompareFunction</p>
<p>Here is the Completed Code</p>
<pre class="brush: as3;">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
			   xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
			   xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot; minWidth=&quot;1024&quot; minHeight=&quot;768&quot;&gt;
	&lt;fx:Declarations&gt;
		&lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt;
		&lt;mx:DateFormatter id=&quot;dateFormatter&quot; formatString=&quot;MMMM D, YYYY&quot; /&gt;

	&lt;/fx:Declarations&gt;
	&lt;fx:Script&gt;
		&lt;![CDATA[
			import mx.collections.ArrayCollection;
			import mx.utils.ObjectUtil;

			[Bindable]
			private var initDG:ArrayCollection = new ArrayCollection([
				{ID:1, datePosted:&quot;03/15/2009&quot;},
				{ID:2, datePosted:&quot;02/18/2009&quot;}
			]);

			private function dateFormat(item:Object, eventGridColumn:DataGridColumn):String
			{
				return dateFormatter.format(item.datePosted);
			}
			private function date_sortCompareFunc(itemA:Object, itemB:Object):int {
				/* Date.parse() returns an int, but
				ObjectUtil.dateCompare() expects two
				Date objects, so convert String to
				int to Date. */
				var dateA:Date = new Date(Date.parse(itemA.date));
				var dateB:Date = new Date(Date.parse(itemB.date));
				return ObjectUtil.dateCompare(dateA, dateB);
			}

		]]&gt;
	&lt;/fx:Script&gt;

	&lt;mx:DataGrid dataProvider=&quot;{initDG}&quot; id=&quot;dg0&quot; x=&quot;0&quot; y=&quot;0&quot; width=&quot;100%&quot; height=&quot;100%&quot;&gt;
		&lt;mx:columns&gt;
			&lt;mx:DataGridColumn headerText=&quot;ID&quot; dataField=&quot;ID&quot; width=&quot;25&quot; /&gt;
			&lt;mx:DataGridColumn headerText=&quot;Date&quot; dataField=&quot;datePosted&quot; sortCompareFunction=&quot;date_sortCompareFunc&quot;
							   labelFunction=&quot;dateFormat&quot;/&gt;
			&lt;/mx:columns&gt;
		&lt;/mx:DataGrid&gt;
&lt;/s:Application&gt;
</pre>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="300" height="150" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://pragmaticflex.com/content/DateFormat/DateFormat.swf" /><embed type="application/x-shockwave-flash" width="300" height="150" src="http://pragmaticflex.com/content/DateFormat/DateFormat.swf"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://PragmaticFlex.com/blog/posts/458/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Object Oriented Thinking for the Procedural Programmer</title>
		<link>http://PragmaticFlex.com/blog/posts/453</link>
		<comments>http://PragmaticFlex.com/blog/posts/453#comments</comments>
		<pubDate>Mon, 07 Dec 2009 20:35:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[introduction]]></category>
		<category><![CDATA[Object Oriented]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[procedural]]></category>

		<guid isPermaLink="false">http://PragmaticFlex.com/blog/?p=453</guid>
		<description><![CDATA[In procedural programming we typically tell the system what to do in a line by line sequence of events. The data being used was globally available to enable various functions to act on it. Many developers today are using a mix of procedural and object oriented techniques. While they may be using an object oriented [...]]]></description>
			<content:encoded><![CDATA[<p>In procedural programming we typically tell the system what to do in a line by line sequence of events. The data being used was globally available to enable various functions to act on it. Many developers today are using a mix of procedural and object oriented techniques. While they may be using an object oriented language and object oriented libraries or tools, the actual code tends to be rather procedural.</p>
<p>Many tutorials use &#8220;Hello World&#8221; as a sample application to teach. Interestingly most of these examples also use this mixed mode.</p>
<p>Look at a simple example</p>
<pre class="brush: as3;">public function sayHello():String
{
	var returnVariable:String=&quot;&quot;;

	var name:String=&quot;Bob&quot;;

	returnVariable= &quot;Hello &quot; + name;

	return returnVariable;
}</pre>
<p>This is really a simple top down procedural approach. So what is Object Oriented programming then. First let’s find out what an object is</p>
<p>What is an Object</p>
<p>You deal with objects every day in the real world. Your coffee mug is an object, your mouse is an object, heck you’re even an object. What does this have to do with programming? When we think in OO for our development we need to think in the same way we do in the real world, about objects. Lets take a few items from the real world and use them in OO programming. First look at your coffee mug. It has some data points or attributes about it such as color, capacity, temperature, available space etc. Some of those elements are fixed and shouldn’t be changed such as color and capacity. There are other attributes that can change such as available space.</p>
<p>Let look at a procedural example</p>
<pre class="brush: as3;">public function showMug():String
{
	var returnVariable:String=&quot;&quot;;

	var mugColor:String=&quot;White&quot;;
	var mugCapacity:String=&quot;14oz&quot;;
	var mugContents:String=&quot;&quot;;
	var mugTempurature:String=&quot;&quot;;
	var mugAvailableSpace:String=&quot;&quot;;

	//Fill mug with coffee
	mugContents = &quot;12oz Coffee&quot;;
	mugTemperature = &quot;Hot&quot;;
	mugAvailableSpace = &quot;0&quot;;

	// Check out our mug
	returnVariable=returnVariable + &quot;Color: &quot; + mugColor + &quot;\n&quot;;
	returnVariable=returnVariable + &quot;Capacity: &quot; + mugCapacity + &quot;\n&quot;;
	returnVariable=returnVariable + &quot;Contents: &quot; + mugContents + &quot;\n&quot;;
	returnVariable=returnVariable + &quot;Temperature: &quot; + mugTempurature + &quot;\n&quot;;
	returnVariable=returnVariable + &quot;Available Space: &quot; + mugAvailableSpace + &quot;\n&quot;;

	return returnVariable;
}
</pre>
<p>Pretty straight forward. There are a few challenges though. How do you ensure I can’t put in more than the capacity. What’s to keep line of code from changing the temperature, color, or capacity. And finally  how do you deal with more than one mug. Yes you can code for a lot of these issues procedurally but the code gets complex and really you can&#8217;t enforce the rules you put in place since the objects are global.  Object Oriented programming allows you to do this.</p>
<p>In an OO model we would have a mug, or multiple mugs, each with its own current status. Once we got our mug, nothing would be able to change the color or capacity. While the temperature may change over time, this should be determined by the mug not some other code. For example I have a thermal mug which keeps my coffee hot for 2 hours. But I also have a regular ceramic mug that only keeps it warm for 20 minutes. The mug really determines how the temperature changes.</p>
<p>So lets make a mug</p>
<p>This mug and all objects really is just an isolated bit of code that can be reused. There are some rules for Objects but we won’t worry about them now.</p>
<pre class="brush: as3;">package
{
	public class Mug
	{
		// define the various attributes but don't set them
		// Mark them private so they can't be updated by anyone but this mug
		private var _mugColor:String=&quot;White&quot;;
		private var _mugCapacity:String=&quot;14oz&quot;;
		private var _mugContents:String=&quot;&quot;;
		private var _mugTempurature:String=&quot;&quot;;
		private var _mugAvailableSpace:String=&quot;&quot;;

		// create an initialization function or constructor
		// that will be used to setup some attribute data
		public function Mug(color:String, capacity:String)
		{
			_mugColor=color;
			_mugCapacity=capacity;
			_mugTempurature=&quot;HOT!&quot;;
		}

		//enable the contents to be set
		public function set mugContents(value:String):void
		{
			_mugContents = value;
		}

		// enable everyone to see what our attributes are
		public function get mugColor():String
		{
			return _mugColor;
		}

		public function get mugCapacity():String
		{
			return _mugCapacity;
		}

		public function get mugContents():String
		{
			return _mugContents;
		}

		public function get mugTempurature():String
		{
			return _mugTempurature;
		}

		public function get mugAvailableSpace():String
		{
			return _mugAvailableSpace;
		}

	}
}
</pre>
<p>Now lets use it</p>
<pre class="brush: as3;">public function showMug():String
{
	var returnVariable:String=&quot;&quot;;

	var mug1:Mug=new Mug(&quot;White&quot;,&quot;14oz&quot;);

	//Fill mug with coffee
	mug1.mugContents = &quot;Coffee&quot;;

	// Check out our mug
	returnVariable=returnVariable + &quot;Color: &quot; +  mug1.mugColor + &quot;\n&quot;;
	returnVariable=returnVariable + &quot;Capacity: &quot; + mug1.mugCapacity + &quot;\n&quot;;
	returnVariable=returnVariable + &quot;Contents: &quot; + mug1.mugContents + &quot;\n&quot;;
	returnVariable=returnVariable + &quot;Temperature: &quot; + mug1.mugTempurature + &quot;\n&quot;;
	returnVariable=returnVariable + &quot;Available Space: &quot; + mug1.mugAvailableSpace + &quot;\n&quot;;

	return returnVariable;
}</pre>
<p>At first it appears we just added some structure to our code and split this into two files. If you look closer you&#8217;ll see that we can&#8217;t change the color or capacity after we get our mug.</p>
<p>Lets make this into a coffee shop and use lots of mugs.</p>
<pre class="brush: as3;">public function showMug():String
{
	var returnVariable:String=&quot;&quot;;

	var mug1:Mug=new Mug(&quot;White&quot;,&quot;14oz&quot;);

	//Fill mug with coffee
	mug1.mugContents = &quot;Coffee&quot;;

	var mug2:Mug = new Mug(&quot;Silver&quot;, &quot;8oz&quot;);
	mug1.setContents(&quot;Tea&quot;);

	var mug31:Mug = new Mug(&quot;Red&quot;, &quot;6oz&quot;);
	mug1.setContents(&quot;Chai&quot;);

	var mug4:Mug = new Mug(&quot;Blue&quot;, &quot;12oz&quot;);
	mug1.setContents(&quot;Hot Chocolate&quot;);

	var mug5:Mug = new Mug(&quot;Black&quot;, &quot;10oz&quot;);
	mug1.setContents(&quot;Milk&quot;)

	outputMug(mug1);
	outputMug(mug2);
	outputMug(mug3);
	outputMug(mug4);
	outputMug(mug5);

	return returnVariable;
}

private function outputMug(mug:Mug):String {
	var returnVariable:String=&quot;&quot;;

	returnVariable=returnVariable + &quot;Color: &quot; +  mug1.mugColor + &quot;\n&quot;;
	returnVariable=returnVariable + &quot;Capacity: &quot; + mug1.mugCapacity + &quot;\n&quot;;
	returnVariable=returnVariable + &quot;Contents: &quot; + mug1.mugContents + &quot;\n&quot;;
	returnVariable=returnVariable + &quot;Temperature: &quot; + mug1.mugTempurature + &quot;\n&quot;;
	returnVariable=returnVariable + &quot;Available Space: &quot; + mug1.mugAvailableSpace + &quot;\n&quot;;

	return returnVariable;
}</pre>
<p>Not much extra code and lost of reuse.</p>
<p>This has been a very brief intro to Object oriented programming. There is a lot more to OO, but taking these first steps will reduce the amount of code you need to write as well as increasing the quality of your application.</p>
]]></content:encoded>
			<wfw:commentRss>http://PragmaticFlex.com/blog/posts/453/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unit Testing with FlexUnit</title>
		<link>http://PragmaticFlex.com/blog/posts/450</link>
		<comments>http://PragmaticFlex.com/blog/posts/450#comments</comments>
		<pubDate>Mon, 07 Dec 2009 19:02:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://PragmaticFlex.com/blog/?p=450</guid>
		<description><![CDATA[Whether you’re the sole developer of an application or you’re part of a large team, writing tests for you code is the key to a quality product. In this article, Kelly Brown introduces FlexUnit and discusses how to start writing unit test for your application.
Read Kelly Brown&#8217;s article on Unit Testing with FlexUnit
]]></description>
			<content:encoded><![CDATA[<p>Whether you’re the sole developer of an application or you’re part of a large team, writing tests for you code is the key to a quality product. In this article, Kelly Brown introduces FlexUnit and discusses how to start writing unit test for your application.</p>
<p><a href="http://www.insideria.com/2008/04/unit-testing-with-flexunit-1.html">Read Kelly Brown&#8217;s article on Unit Testing with FlexUnit</a></p>
]]></content:encoded>
			<wfw:commentRss>http://PragmaticFlex.com/blog/posts/450/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating server after DataGrid edits &#8211; Dealing with event handler priorities</title>
		<link>http://PragmaticFlex.com/blog/posts/440</link>
		<comments>http://PragmaticFlex.com/blog/posts/440#comments</comments>
		<pubDate>Fri, 27 Nov 2009 17:46:01 +0000</pubDate>
		<dc:creator>cgrant</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[Event Handler]]></category>
		<category><![CDATA[Event Priority]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Example]]></category>

		<guid isPermaLink="false">http://christophergrant.info/blog/2009/11/27/updating-server-after-datagrid-edits-dealing-with-event-handler-priorities/</guid>
		<description><![CDATA[The DataGrid component updates its dataprovider after an edit using the DataGridEvent.ITEM_EDIT_END event. When trying to access the updated data using this same event it's important to register your handler using proper priorities so you can access the updated data rather than the original data.]]></description>
			<content:encoded><![CDATA[<p>In this example we’re looking at sending a server request to update data from a Flex DataGrid after a user has edited a field. What we want to do is automatically save the data to the backend when a user leaves an editable field.</p>
<p>The datagrid fires off an event when the user is done editing. Setting up a handler for  DataGridEvent.ITEM_EDIT_END can be done right on the MXML or in ActionScript. The MXML version is very straight forward.</p>
<pre class="brush: plain;">&lt;mx:DataGrid
id=”dg”
dataProvider=&quot;{dgCollection}&quot;
itemEditEnd=&quot;endHandler(event)&quot;
editable=&quot;true&quot;&gt;</pre>
<p>The problem here is that this fires before the datagrid updates the data provider with the edits. In this case the endHandler function only has access to the original values.</p>
<p>As <a href="http://www.adobe.com/devnet/flash/articles/detecting_datagrid_edits.html" target="_blank">Paul Robertson notes in his article on this</a> the DataGrid registers its own handler for this event. When adding event handlers you can optionally add a priority, and in this case the DataGrid handler is –50 in priority and our endHandler is using the default 0. Which means our function fires before the datagrid’s function.</p>
<p>In order to gain access to the updated results on the dataprovider we need to register our handler AFTER the datagrid updates the provider. To do this we need to switch over and user the ActionScript moethod of handler registration instead of the MXML style.</p>
<p>We register our handler in ActionScript with a priority less than –50</p>
<pre class="brush: plain;">dg.addEventListener(
DataGridEvent.ITEM_EDIT_END,
endHandler,
false,
-100);</pre>
<p>Now when endHandler fires it will be accessing the updated values</p>
<p>Here is the complete code</p>
<pre class="brush: plain;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot; minWidth=&quot;1024&quot; minHeight=&quot;768&quot;
creationComplete=&quot;creationCompleteHandler(event);&quot;&gt;
&lt;fx:Declarations&gt;
&lt;mx:RemoteObject id=&quot;ro&quot; destination=&quot;DGSource&quot; result=&quot;resultAllEvents&quot; /&gt;
&lt;/fx:Declarations&gt;
&lt;fx:Script&gt;
&lt;![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
import mx.events.DataGridEvent;
[Bindable]
private var dgCollection:ArrayCollection;
private function creationCompleteHandler(event:FlexEvent):void
{
dg.addEventListener(DataGridEvent.ITEM_EDIT_END, endHandler,false,-100);
}
private function resultAllEvents(evt:ResultEvent):void
{
var e:ArrayCollection = evt.result as ArrayCollection;
dgCollection=e;
}
public function endHandler(event:DataGridEvent):void
{
ro.saveOrUpdateEvent(dg.selectedItem);
}

]]&gt;
&lt;/fx:Script&gt;
&lt;mx:Button x=&quot;168&quot; y=&quot;10&quot; label=&quot;Get Events&quot; width=&quot;343&quot; click=&quot;ro.getOperation('findAll').send();&quot; height=&quot;21&quot;/&gt;
&lt;mx:DataGrid
dataProvider=&quot;{dgCollection}&quot;
id=&quot;dg&quot; editable=&quot;true&quot;
&gt;
&lt;mx:columns&gt;
&lt;mx:DataGridColumn headerText=&quot;Date&quot; dataField=&quot;date&quot;/&gt;
&lt;mx:DataGridColumn headerText=&quot;Title&quot; dataField=&quot;title&quot;/&gt;
&lt;/mx:columns&gt;
&lt;/mx:DataGrid&gt;
&lt;/s:Application&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://PragmaticFlex.com/blog/posts/440/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is source control and how to get started</title>
		<link>http://PragmaticFlex.com/blog/posts/439</link>
		<comments>http://PragmaticFlex.com/blog/posts/439#comments</comments>
		<pubDate>Thu, 26 Nov 2009 16:01:41 +0000</pubDate>
		<dc:creator>cgrant</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Setup]]></category>
		<category><![CDATA[Source Control]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[SVN]]></category>
		<category><![CDATA[Versioning]]></category>

		<guid isPermaLink="false">http://christophergrant.info/blog/2009/11/26/what-is-source-control-and-how-to-get-started/</guid>
		<description><![CDATA[A source control system may seem overly complicated and unnecessary. Fortunately they’re not as cumbersome as you might think and the benefits are well worth the small effort.  In this post, we'll show some of the reasons to use a source control system and the basics of starting to use one.]]></description>
			<content:encoded><![CDATA[<p>In the big IT shops source control is rather common place. However in smaller shops or for individual developers a version control system may not be a top priority. A source control system may seem overly complicated and unnecessary. Fortunately they’re not as cumbersome as you might think and the benefits are well worth the small effort.</p>
<p>So what exactly do we mean when we talk about source control, or version control systems? Basically a source control system provides a central place to store your code and a mechanism to track revisions of that code.</p>
<h3></h3>
<h3>Source Control</h3>
<p>One common reason people start using a source control system is when more than one developer needs to access the code. There used to be a time when our live production system served as the central repository for accessing code. Jim had a task to update a webpage so, he would connect directly to the server and make a change to the file in the live environment. Bob may have a change to make and then go do the same thing. What about quality, what if there was a mistake or a file was accidentally deleted. To avoid this Developers may keep code in another location other than the live site. For individual developers this is typically on their computer. For multiple developers, this central spot may be a shared network drive. With that risk averted what else could go wrong?</p>
<p>What if Jim had a lot of changes to implement. Some core functionality needed to be changed and it couldn’t be done at one time. Typically Jim would grab a copy and keep it locally until it was finished then post it. Here’s the rub, after Jim takes the copy but before he puts it back, Bob goes on the server and makes a change. Later Jim posts his changes and overwrites Bob’s code. Geez thanks Jim.</p>
<p>Here’s where we start to see features of a source control system come in. In this case if they were using source control, when Jim tries to put his changes in, the system would alert him that other changes had been made since he pulled his copy.</p>
<h3>Source Versioning</h3>
<p>So what about this versioning concept, why do I care? Have you ever used undo on your computer? You know you make a mistake, hit ctrl+z and revert back to what you had before? Here’s a question, how do you revert back to something you had yesterday or last week. If you had something versioning your files you could do just that.</p>
<p>Say you’re doing a website and are making some wording updates to a promotion. You post the changes and a few weeks later your client tells you there’s a law suit over that change. Apparently a customer claimed the original promotion said one thing but the company say it was something else. How do you go back and see what really was on the site? Version control.</p>
<p>Another scenario, you have a functional application that your client is using in production. Now you have another customer who wants to use it too. You decide to update the application to accommodate more than one client. After a few weeks of tinkering you still can’t get things the way you want. It’s functional and in your central repository but not quite right. Your client comes back and wants a change to the app in production tomorrow. Your repository copy has the new changes in it, if you make the change now it will have your unfinished changes in it. With a version control system you can pull a snapshot of the code from before you started your changes and update it without affecting your in progress changes.</p>
<h3>Getting started using a source version control system</h3>
<p>There are a variety of free and fee based solutions. Some of the big names like ClearCase and Preforce sometimes show up in the big companies but the free solutions like CVS and SVN are more popular. CVS has been around for ages and had a huge following. SVN, also known as Subversion, started as an effort to fix some of the challenges that were in CVS. These days SVN is very widely used and is pretty much the standard.</p>
<p>Lets take a look at SVN. Most systems have a server component and a client component. The server piece is where your code is stored and the client is an interface for you to access that code. SVN is no different. You can go out and <a href="http://subversion.tigris.org/" target="_blank">grab the server components</a> then go get a client too. You don’t need to do this at this point though. For this example and for simple setups, the <a href="http://tortoisesvn.tigris.org/" target="_blank">Subversion client TortoiseSVN</a> has everything you need. So go ahead, down load and install it.</p>
<p>Once installed create a directory to act as your central repository. In this case I’ll create one at c:\repo. Navigate into that directory and right click. In the context menu choose TortoiseSVN -&gt; Create repository here. Just like that you have a functional source control system.</p>
<p>Lets start using our new system. Before we do I need to clarify one thing. We just created a setup that mimics a server configuration. While this example is setup locally, it could ba on a server somewhere. The next step explains how you access that content and keep a useable copy locally.</p>
<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image15.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb17.png" border="0" alt="image" width="339" height="266" align="right" /></a> We’re ready now to use our SVN instance. Find a place on your computer where you’ll be doing your work, maybe c:\workspace. Navigate into that directory and right click. In the context menu choose SVN Chekout. This will pop up a window asking you where your repository is and how you want to get the contents.</p>
<p>For the URL type in <a href="file:///">file:///</a> followed by the path to where you create the SVN repository earlier. This is not the working directory, rather the location of the repository. Since we installed this locally it will be something like <a href="file:///C:/repo">file:///C:/repo</a> but if this were on a server it could be <a href="http://someserver.com/repo">http://someserver.com/repo</a></p>
<p>In this scenario we’re starting with the repository and pull the contents into our workspace. If you already had files in a workspace you could start there and push them into the repository with the import option on the context menu.</p>
<h3>Using Your New Source Control System</h3>
<p>Now that we have things setup lets try it out. Create a text file in your workspace called MyFile.txt. Add some content in it. Save and close. <a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image16.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb18.png" border="0" alt="image" width="244" height="150" /></a>Depending on your version and setup the icon may differ but you’ll see a marker on your file like a question mark. This is telling you that this file is not in the repository or under source control. Since it is a new file we need to get it in there. Right click on a white space and choose</p>
<p>svn commit. The following popup will show you all files   that have been updated locally and are not in sync with the repository. you should notice that our file is listed, but is not checked.<a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image17.png"><img style="border: 0pt none; display: block; margin-left: auto; margin-right: auto;" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image17.png" border="0" alt="image" /></a> Since this is a new file we need to select it and have the SVN client add it to our repository. Make sure our file is checked and hit ok.  The confirmation screen will show that everything has been added and updated.</p>
<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image18.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb20.png" border="0" alt="image" width="244" height="114" /></a>Now go back and make a change to that file again, Save it and take a look at the new icon.</p>
<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image19.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb21.png" border="0" alt="image" width="146" height="145" /></a></p>
<p>This exclamation point tells us that this file, which is under version control, is out of sync with the repository. Again right click and commit changes.</p>
<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image20.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb22.png" border="0" alt="image" width="105" height="104" /></a> Now all is good and we get a Green check mark.</p>
<p>So there you have it. The bare bones basics of getting going with a source control system.</p>
<p>In future posts we’ll be using source control systems in our examples which will give you more context how this fits into a development process. Even with this basic setup you’ll be able to point your IDE to this local repository and follow along. Don’t just use it for our examples though, you can keep versions of any file this way. Version your wedding list, or Photoshop files. Whatever it is, revision control systems provide a lot of value.</p>
<p>For now happy versioning.</p>
]]></content:encoded>
			<wfw:commentRss>http://PragmaticFlex.com/blog/posts/439/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex development on the cheap (free)</title>
		<link>http://PragmaticFlex.com/blog/posts/426</link>
		<comments>http://PragmaticFlex.com/blog/posts/426#comments</comments>
		<pubDate>Wed, 25 Nov 2009 16:13:10 +0000</pubDate>
		<dc:creator>cgrant</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[FlashDevelop]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://christophergrant.info/blog/2009/11/25/flex-development-on-the-cheap-free/</guid>
		<description><![CDATA[For organizations based on open source tools, or a developer not looking to spend alot on an IDE, FlashDevelop offers a free alternative to full fledged IDEs. This tool provides many of the core features needed by developers for free. A great tool for anyone looking for a free alternative to Flex Builder]]></description>
			<content:encoded><![CDATA[<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="right" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb15.png" width="244" height="219" /></a>When introducing Flex in my organization there was a bit of pushback on the Flex Builder licenses. Being the Java shop the we are, free is just the way it works. We’re so used to using free tools like Eclipse that we question paying for anything. This reminded me of when I was trying to learn ActionScript way back and had to have a copy of Flash to work through things. </p>
<p>&#160;</p>
<p>So here you are, don’t want to buy Flex Builder but you do want to learn flex. Sure there is a 30day trial but what will you do after that?</p>
<p>There are a few tools available that allow you to code in ActionScript / Flex for free. One of the popular ones is <a href="http://www.flashdevelop.org/" target="_blank">FlashDevelop</a> is <a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image14.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="left" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb16.png" width="116" height="110" /></a>a free IDE for developing apps for the Flash Platform. FlashDevelop is a basic IDE that provides code insight, project management, and integrated compilation. There are a <a href="http://www.flashdevelop.org/wikidocs/index.php?title=Getting_Started" target="_blank">few steps to install</a>,such as pointing to the Flex3 SDK and the location of your Flash Player, but that&#8217;s it. </p>
<p>Create a new project, write some code and you’re good to go. Flex development with no strings attached. </p>
<p>Check out <a href="http://www.flashdevelop.org/" target="_blank">FlashDevelop</a>, it’s a great tool for Flex development.</p>
]]></content:encoded>
			<wfw:commentRss>http://PragmaticFlex.com/blog/posts/426/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to fix problems with combined Flex / J2EE projects and BlazeDS</title>
		<link>http://PragmaticFlex.com/blog/posts/421</link>
		<comments>http://PragmaticFlex.com/blog/posts/421#comments</comments>
		<pubDate>Tue, 24 Nov 2009 21:45:17 +0000</pubDate>
		<dc:creator>cgrant</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[Flex J2EE]]></category>
		<category><![CDATA[Setup]]></category>

		<guid isPermaLink="false">http://christophergrant.info/blog/2009/11/24/how-to-fix-problems-with-combined-flex-j2ee-projects-and-blazeds/</guid>
		<description><![CDATA[Flex Builder and Flash Builder both have the ability to setup a few aspects of your BlazeDS project for you. It sounds nice, but it may not be the best solution. This post talks about some of the pitfalls with the automated process and walks through setting up Flash Builder with BlazeDS manually to avoid those problems.]]></description>
			<content:encoded><![CDATA[<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image7.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="right" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb9.png" width="244" height="172" /></a> Flex Builder and Flash Builder both have the ability to setup a few aspects of your BlazeDS project for you. In a previous posting I explained how to set up a BlazeDS project in Flash Builder. When you select “Use remote object access service” you’re telling the IDE to set up a few things for you. Selecting this keeps you from having to import the BlazeDS libraries, add configuration files and set a compiler option that points to the config files. </p>
<p>It sounds nice, but it may not be the best solution. Flash Builder seems to be a bit buggy when you choose this option. As of this posting it seems to incorrectly set the web context for the destination call when making the actual AMF call. More specifically it seems to use the “WebContent” value instead of “WebContext”. The result is that the calls are made to <a href="http://localhost:8080/WebContent/messagebroker/amf">http://localhost:8080/WebContent/messagebroker/amf</a> instead of <a href="http://localhost:8080/MyProject/messagebroker/amf">http://localhost:8080/MyProject/messagebroker/amf</a>. While this may be a bug in the beta version of Flash Builder there are other reasons not to trust this to your IDE. </p>
<p>When you set this up automatically, the config files are put into your WEB-INF/flex directory for you. When you edit these files, Flash Builder prompts you asking you if you really want to do this since they are generated files. Typically you would just hit yes and update the files. Here’s the rub. If you go under the project properties and change the server configuration the IDE may delete those files from the directory. In FlashBuilder if you remove the BlazeDS support after a project has been set up it removes the config files. Why would you do this if you were writing a BlazeDS app? Well maybe someone (me) was trying to fix the destination issue I previously mentioned by changing the WebContext setting. This setting happens to be locked down in an automated setup. </p>
<p>Finally when your application gets all growed up and wants to move out, you’ll probably want to move the build process to a command line utility. At this point you’ll have to know about the libraries, config files and compiler options anyway. So why wait, just set it up on your own to begin with.&#160;&#160; FlashBuilder isn’t really doing that much anyway. </p>
<p>&#160;</p>
<h2>Set it up yourself</h2>
<p>So where to begin. Lets talk briefly about the three main styles of setup that you&#8217;ll come across online. First is what we already mentioned, having Flash Builder setup things for you in a combined Flex J2EE project. The second way many sites discuss is creating a project for flex and pointing it to an existing server that’s running BlazeDS.&#160; This is a more prevalent option and highlights the separation of concerns that actually exists in any final solution. The third method is to manually create a combined Flex J2EE project. This third option is more ideal for smaller projects. </p>
<p>&#160;</p>
<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image8.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="right" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb10.png" width="336" height="121" /></a> Lets look at setting up Flash Builder with BlazeDS manually. Go ahead and create a new flash project. Select J2EE for server technology, but DON’T select use remote object access. I have WTP installed so I have Flash Builder create my web app for me by selecting Create combined J2EE/Flex project using WTP. </p>
<p>Finish the set up as usual. Now you’ll need that BlazeDS war everyone talks about. If you don’t have it yet go get it from the Adobe <a href="http://opensource.adobe.com/wiki/display/blazeds/Release+Builds" target="_blank">Release Builds page</a>. You can just grab the Binary Distribution. The Turnkey version just includes a lot of stuff we don’t need right now. </p>
<p>Once you get the War we’ll need to import it into <a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image9.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="left" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb11.png" width="154" height="43" /></a>our project. Go to File –&gt; Import then select Archive file under General. Locate the directory where you put the blazeds.war and switch the file type to *.* then select the war. </p>
<p>&#160;</p>
<p>Now we don’t need everything in this war, sure you can import it all but lets keep things clean. </p>
<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image10.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="right" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb12.png" width="244" height="165" /></a>Deselect the META-INF, classes and src directories. Also you’ll need to change the import into folder field from &lt;project&gt; to &lt;project&gt;/WebContent.</p>
<p>Hit Finish and say yes to overwriting web.xml. See that wasn’t so bad and you just did most of what FlashBuilder did, simply by importing that war yourself. </p>
<p>&#160;</p>
<p>There is one other thing we need to do before we’re done. The web.xml tells Java where to find the configuration files but we need to let flex know also. It’s pretty easy, just follow my lead. </p>
<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image11.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="left" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb13.png" width="167" height="46" /></a>Open up the project properties and head to flex compiler. See that field additional compiler arguments?&#160; We’re going to update it. </p>
<p>We want to add a compiler option pointing to the configuration files. You can use either a path that&#8217;s in the classpath&#160; or a physical location on your drive. We’ll use the latter. Update the Additional compiler arguments to include the following –services “C:\dev\MyProject\WebContent\WEB-INF\flex\services-config.xml” where dev is your workspace directory and MyProject is your project name.&#160; </p>
<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image12.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb14.png" width="476" height="52" /></a> </p>
<p>Hit OK&#160; and you’re done.</p>
<p>&#160;</p>
<p>&#160;</p>
<p>Setting this up manually is a good practice and will make things easier later when we migrate to Maven and Ant. Stay Tuned!!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://PragmaticFlex.com/blog/posts/421/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connecting Flex to Java with BlazeDS</title>
		<link>http://PragmaticFlex.com/blog/posts/387</link>
		<comments>http://PragmaticFlex.com/blog/posts/387#comments</comments>
		<pubDate>Sat, 21 Nov 2009 03:03:53 +0000</pubDate>
		<dc:creator>cgrant</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Configuration]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[FlashBuilder]]></category>
		<category><![CDATA[FlexBuilder]]></category>
		<category><![CDATA[Integration]]></category>

		<guid isPermaLink="false">http://christophergrant.info/blog/2009/11/20/connecting-flex-to-java-with-blazeds/</guid>
		<description><![CDATA[BlazeDS offers a great mechanism to attach your flex application to backend services. In this brief overview we’ll configure flex to call a Java Class and return results.]]></description>
			<content:encoded><![CDATA[<p>BlazeDS offers a great mechanism to attach your flex application to backend services. In this brief overview we’ll configure flex to call a Java Class and return results. This overview assumes you’ve already setup your IDE with a basic Flex / BlazeDS project.</p>
<h3>Main points we’ll cover</h3>
<ul>
<li>Build the Java Class</li>
<li>Expose the Class with Blaze on the server</li>
<li>Configure Flex to find the Blaze service</li>
<li>Build the Flex components to make the call</li>
</ul>
<p><span id="more-387"></span></p>
<h3>Build the Java Class</h3>
<p>In your IDE switch to the Java view and create a new Java class. We’ll call it HelloFlex. Create a private variable called message. Set an initial value for this variable in the constructor. Finally create a getter method that returns the message string.</p>
<pre class="brush: plain;">package com.grant;

public class HelloFlex {
private String message;
public HelloFlex(){
message=&quot;HI Flex. this is Java. How are you?&quot;;
}
public String getMessage(){
return message;
}
}
</pre>
<h3>Expose the class with BlazeDS on the server</h3>
<p>Under your web-inf directory you’ll fine a subdirectory called flex. Within there you’ll see the main config files blaze uses to set up the services. services-config.xml is the main file and has statements to include the others. For this example we’re creating a simple remoting service, so go ahead and open up the  remoting-config.xml. Here’s where we’ll set up the configuration for our reomting service.</p>
<p>Blaze calls exposed services destinations. In this remoting-config.xml we’ll set up a destination that points to our HelloFlex class.</p>
<p>Under the default-channels create a new destination as follows.</p>
<pre class="brush: plain;">
    &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    &lt;service id=&quot;remoting-service&quot;
    class=&quot;flex.messaging.services.RemotingService&quot;&gt;

    &lt;adapters&gt;
    &lt;adapter-definition id=&quot;java-object&quot; class=&quot;flex.messaging.services.remoting.adapters.JavaAdapter&quot; default=&quot;true&quot;/&gt;
    &lt;/adapters&gt;

    &lt;default-channels&gt;
    &lt;channel ref=&quot;my-amf&quot;/&gt;
    &lt;/default-channels&gt;

    &lt;destination id=&quot;helloflex&quot;&gt;
    &lt;properties&gt;
    &lt;source&gt;com.grant.HelloFlex&lt;/source&gt;
    &lt;/properties&gt;
    &lt;adapter ref=&quot;java-object&quot; /&gt;
    &lt;channels&gt;
    &lt;channel ref=&quot;my-amf&quot; /&gt;
    &lt;/channels&gt;
    &lt;/destination&gt;
    &lt;/service&gt;
</pre>
<h3>Configure Flex to find the BlazeDS Service</h3>
<p>Depending how you set up your workspace that set may already be done for you. In order for flex to know what channels and destinations are available, our application needs to know where these config files are. In Java, these files are in the class path and are included in the build process. In Flex we need to explicitly tell the compiler where these files are.</p>
<p>Right click on the project and choose properties. Under flex compiler you’ll see a textbox for additional compiler arguments. To configure the file location you’ll need an argument here called services which points to the location of your xml files.</p>
<p>You have two options now.</p>
<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb6.png" border="0" alt="image" width="209" height="48" align="right" /></a>1) If the folder is part of your flex build path you can make a relative reference to the file using the &#8211;services=&lt;file&gt; format as follows. Notice the web-inf directory is not included in the definition. In this the folder containing the flex subfolder is on my build path.</p>
<p>2) If the folder is NOT on your build path you can point to the file location. This is the default method that FlashBuilder implements. We’ll use it for this example, however I suggest <a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image5.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb7.png" border="0" alt="image" width="402" height="44" align="right" /></a>you move to a relative location style as soon as you can.</p>
<p>For an explicit file system location the flex option is slightly different. Here we use the –services “&lt;file Location&gt;” format. On my drive the option reads</p>
<pre class="brush: plain;">–services &quot;C:\FlashBuilder\dev\MyProject\WebContent\WEB-INF\flex\services-config.xml&quot;</pre>
<h3>Build the Flex components to make the call</h3>
<p>Now we can get back to our flex components and make the actual call. First flip back over to your Flex Perspective and open your main mxml file.</p>
<p>First we’ll define the service:</p>
<pre class="brush: plain;">&lt;mx:RemoteObject id=&quot;myService&quot;  destination=&quot;helloflex&quot; /&gt;</pre>
<p>The id is the name you’ll reference this service elswhere in your flex app. The destination of helloflex needs to match the destination name you entered in your remoting-config.xml</p>
<p>Next we’ll move to some visual components. First lets add a panel to hold our controls.</p>
<pre class="brush: plain;">&lt;s:Panel width=&quot;100%&quot; height=&quot;100%&quot;&gt;
   &lt;s:layout&gt;
      &lt;s:VerticalLayout/&gt;
   &lt;/s:layout&gt;
&lt;/s:Panel&gt;</pre>
<p>And add a text box to display some results</p>
<pre class="brush: plain;">
    &lt;s:Panel width=&quot;100%&quot; height=&quot;100%&quot;&gt;
       &lt;s:layout&gt;
          &lt;s:VerticalLayout/&gt;
       &lt;/s:layout&gt;

    &lt;mx:TextArea id=&quot;result_text&quot;/&gt;

    &lt;/s:Panel&gt;
</pre>
<p>Now we’ll add a button on the page to use the service</p>
<pre class="brush: plain;">    &lt;s:Panel width=&quot;100%&quot; height=&quot;100%&quot;&gt;
     &lt;s:layout&gt;
     &lt;s:VerticalLayout/&gt;
     &lt;/s:layout&gt;

    &lt;mx:TextArea id=&quot;result_text&quot;/&gt;
     &lt;mx:Button label=&quot;Call Java&quot; click=&quot;myService.getOperation('getMessage').send();&quot;/&gt;

    &lt;/s:Panel&gt;
</pre>
<p>This is a direct use of the RemoteObject myService. This is not a best practice. Typically you would have a function managing your calls and the button would utilize that function. For simplicity sake I’ve included the direct call for this demonstration. In this example you’ll notice we use the getOperation function and pass in the java method name we want to call.</p>
<p>If you were to run this now you would see no results. We have yet to define what happens when the service gets called. Lets do that now.</p>
<p>Create a script block to hold our action script and add a simple method that puts the response of our service in our textbox.</p>
<pre class="brush: plain;">&lt;fx:Script&gt;
 &lt;![CDATA[
 import mx.rpc.events.ResultEvent;
 import mx.rpc.events.FaultEvent;
 private function resultHandler(evt:ResultEvent):void
 {
 result_text.text = evt.message.body.toString();
 }
 ]]&gt;
 &lt;/fx:Script&gt;
</pre>
<p>To use this function we’ll go back to the service and add a handler to manage all responses.</p>
<pre class="brush: plain;">
&lt;fx:Declarations&gt;
 &lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt;
 &lt;!-- DEFINE REMOTE SERVICES WE'LL USE --&gt;
 &lt;mx:RemoteObject
 id=&quot;myService&quot;
 destination=&quot;helloflex&quot;
 result=&quot;resultHandler(event)&quot; /&gt; &lt;/fx:Declarations&gt;</pre>
<p>Your completed code should look like this</p>
<pre class="brush: as3;">    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
     xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
     xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot; minWidth=&quot;1024&quot; minHeight=&quot;768&quot;&gt;
     &lt;fx:Declarations&gt;
     &lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt;
     &lt;!-- DEFINE REMOTE SERVICES WE'LL USE --&gt;
     &lt;mx:RemoteObject
     id=&quot;myService&quot;
     destination=&quot;helloflex&quot;
     result=&quot;resultHandler(event)&quot; /&gt;
     &lt;/fx:Declarations&gt;
     &lt;fx:Script&gt;
     &lt;![CDATA[
     import mx.rpc.events.ResultEvent;
     import mx.rpc.events.FaultEvent;
     private function resultHandler(evt:ResultEvent):void
     {
     result_text.text = evt.message.body.toString();
     }
     ]]&gt;
     &lt;/fx:Script&gt;
     &lt;s:Panel width=&quot;100%&quot; height=&quot;100%&quot;&gt;
     &lt;s:layout&gt;
     &lt;s:VerticalLayout/&gt;
     &lt;/s:layout&gt;
     &lt;mx:TextArea id=&quot;result_text&quot;/&gt;
     &lt;mx:Button label=&quot;Call Java&quot; click=&quot;myService.getOperation('getMessage').send();&quot;/&gt;
     &lt;/s:Panel&gt;

    &lt;/s:Application&gt;
</pre>
<p>That’s it! Run the application and pat yourself on the back. Congratulations! Your first end to end Flex-Java app.</p>
<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb8.png" border="0" alt="image" width="648" height="319" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://PragmaticFlex.com/blog/posts/387/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up Flex BlazeDS in FlashBuilder</title>
		<link>http://PragmaticFlex.com/blog/posts/370</link>
		<comments>http://PragmaticFlex.com/blog/posts/370#comments</comments>
		<pubDate>Thu, 19 Nov 2009 18:23:44 +0000</pubDate>
		<dc:creator>cgrant</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[FlashBuilder]]></category>
		<category><![CDATA[Remoting]]></category>
		<category><![CDATA[Setup]]></category>

		<guid isPermaLink="false">http://christophergrant.info/blog/2009/11/19/setting-up-flex-blazeds-in-flashbuilder/</guid>
		<description><![CDATA[One of the most compelling aspects of Flex is its ability to integrate with a wide variety of data sources. Many of the introductory tutorials online teach how to connect to http services to pull data. The result is typically an XML response. Flex makes it easy to manage XML but there are better ways. [...]]]></description>
			<content:encoded><![CDATA[<p><img style="display: inline; margin-left: 0px; margin-right: 0px" src="http://opensource.adobe.com/wiki/download/attachments/1114252/blazeds_high_119x125.jpg" alt="" align="right" />One of the most compelling aspects of Flex is its ability to integrate with a wide variety of data sources. Many of the introductory tutorials online teach how to connect to http services to pull data. The result is typically an XML response. Flex makes it easy to manage XML but there are better ways. using XML requires an object on the server to be serialized to a text format which adds processing time. The response is also larger due to the variety of XML tags that need to be added in order to properly represent the object’s structure. Yes I hear you in the back telling me that JSON is a lighter weight response that doesn’t require all the tags. Regardless the response still needs to be parse out in the client. Finally the contract between client and server is not well defined with straight XML or JSON. Web services do provide a strict contract for the interface that the client can rely on but  the objects are still serialized with extraneous tags used to define the structure.</p>
<p>BlazeDS utilizes AMF to provide direct links between client and server objects. AMF provides access to objects through a binary protocol and eliminates the need to add additional tags that identify the object structure. It also reduces the work in flex to get the data back into a usable flex object.</p>
<p>Lets start working through an example by getting our workspace setup.<span id="more-370"></span></p>
<h2>Initial Setup</h2>
<p>Flex and Java both need to know about BlazeDS and where to look for the libraries and configuration files. FlashBuilder lends a hand with this by automating some of the process.</p>
<p><a href="http://images.google.com/imgres?imgurl=http://sujitreddyg.files.wordpress.com/2009/05/flash_builder_logo.png%3Fw%3D300%26h%3D299&amp;imgrefurl=http://sujitreddyg.wordpress.com/2009/05/18/flex-builder-will-be-named-as-flash-builder/&amp;usg=__q_PmVLdlAef9ojFuxpTEp5AYRnM=&amp;h=299&amp;w=300&amp;sz=352&amp;hl=en&amp;start=4&amp;um=1&amp;tbnid=gKh_1hLOa-SHVM:&amp;tbnh=116&amp;tbnw=116&amp;prev=/images%3Fq%3DFlashbuilder%26hl%3Den%26rls%3Dcom.microsoft:en-us%26um%3D1"><img style="margin: 0px 10px 0px 0px; display: inline" src="http://t3.gstatic.com/images?q=tbn:gKh_1hLOa-SHVM:http://sujitreddyg.files.wordpress.com/2009/05/flash_builder_logo.png%3Fw%3D300%26h%3D299" alt="" width="93" height="93" align="left" /></a>First things first, you’ll need to have FlashBuilder installed. The beta version can be downloaded at <a href="http://labs.adobe.com/technologies/flashbuilder4/">http://labs.adobe.com/technologies/flashbuilder4/</a>.  Also check to make sure you have the WTP extensions installed in eclipse so you can automate creating the web application structure.</p>
<p>Finally for this IDE example we’re going to download the BlazeDS war from adobe at: <a title="http://opensource.adobe.com/wiki/display/blazeds/Release+Builds" href="http://opensource.adobe.com/wiki/display/blazeds/Release+Builds">http://opensource.adobe.com/wiki/display/blazeds/Release+Builds</a> Just download the binary version, we don’t need the full turnkey for this. Once you have it downloaded, extract it to your drive, you should see the blazeds.war when you’re done.</p>
<h3></h3>
<p>In FlashBuilder create a new Flash project. Select J2EE Application server type. Select Remote object access with BlazeDS and the type. Select create combined Java/Flex using WTP. Click next.</p>
<p><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb2.png" border="0" alt="image" width="253" height="304" /></p>
<p>On the next page, for the BlazeDS WAR file, point to the location where you extracted the files from Adobe. The system will pull all the jar files and configs from this war and add them to your project. Click finish.</p>
<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image2.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb3.png" border="0" alt="image" width="295" height="214" /></a></p>
<p>You’ll notice that FlashBuilder loaded all the Jars and Config files as well as setting up the web.xml.<img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb4.png" border="0" alt="image" width="365" height="213" /></p>
<p>The web.xml tells java where to find the config files that BlazeDS needs. Remembering that Flex and Java are compiled separately and both need to know where configuration files are, lets find out where the IDE tells Flex about the config files.</p>
<p>Looking under the project properties under flex compiler you’ll see a compiler option is added for services.</p>
<p><a href="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image3.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" src="http://pragmaticflex.com/blog/wp-content/uploads/2009/11/image_thumb5.png" border="0" alt="image" width="244" height="182" /></a></p>
<p><strong>NOTE:</strong> Without this compiler option Flex would not be able to find the BlazeDS services. When setting up blazeDS manually this flag will needed to be added by hand.</p>
<p><strong>Java vs Flex:</strong> In Java the config files are loaded at run time. To change a value in the property file you simply need to restart the server to make it take effect. In Flex however this is a compile time include which means any changes to the files will need to be rebuilt into the application. Just a little note that may save you some headaches later.</p>
<p>That’s is for the setup.</p>
<p>Next time we’ll look at the code needed to use BlazeDS. Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://PragmaticFlex.com/blog/posts/370/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing TweetDeck and Adobe Air Apps</title>
		<link>http://PragmaticFlex.com/blog/posts/120</link>
		<comments>http://PragmaticFlex.com/blog/posts/120#comments</comments>
		<pubDate>Tue, 11 Nov 2008 15:18:52 +0000</pubDate>
		<dc:creator>cgrant</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://cgrant.wordpress.com/2008/11/11/fixing-tweetdeck-and-adobe-air-apps/</guid>
		<description><![CDATA[ TweetDeck is a great Twitter client that allows you to manage volumes of communication most efficiently. After installing and using TweetDeck   for awhile I closed a few of the content panes. Later I closed a few more. Down to a single pane I accidentally closed that one too. Apparently in the clients (as [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cgrant.files.wordpress.com/2008/11/image7.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" src="http://cgrant.files.wordpress.com/2008/11/image-thumb4.png" alt="image" width="125" height="240" align="left" /></a> <a href="http://www.tweetdeck.com/">TweetDeck</a> is a great Twitter client that allows you to manage volumes of communication most efficiently. After installing and using TweetDeck  <a href="http://cgrant.files.wordpress.com/2008/11/image8.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" src="http://cgrant.files.wordpress.com/2008/11/image-thumb5.png" alt="image" width="79" height="75" align="right" /></a> for awhile I closed a few of the content panes. Later I closed a few more. Down to a single pane I accidentally closed that one too. Apparently in the clients (as of v0.19.3b) there are no options to open new panes anywhere in the main window. All these options are in the content panes themselves. So here i have stuck with this great tool but no way to view any content. What to do. I promptly uninstalled and reinstalled TweetDeck&#8230;no good. Uninstalled TweetDeck all the rest of my <a href="http://www.adobe.com/products/air/">Adobe Air</a> apps then reinstalling the all again. Nope still broke. So I dug a bit and found that the AIR apps can store data locally in cache files. These files apparently aren&#8217;t cleaned up on uninstall. After locating the cache files and a quick reinstall of TweetDeck all is well.</p>
<p><a href="http://cgrant.files.wordpress.com/2008/11/image9.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" src="http://cgrant.files.wordpress.com/2008/11/image-thumb6.png" alt="image" width="94" height="94" align="right" /></a> If you ever have issues with Adobe Air App preferences look for the cache files on your drive. Mine were at C:\Documents and Settings\[user]\Application Data\TweetDeckFast.[guid] and C:\Documents and Settings\[guid]\Application Data\Adobe\AIR\ELS\TweetDeckFast.[guid]</p>
<p>Deleting these files fixed my problems and allowed for a clean reinstall.</p>
]]></content:encoded>
			<wfw:commentRss>http://PragmaticFlex.com/blog/posts/120/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
