<?xml version="1.0" encoding="utf-8"?>

			<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">

			<channel>
			<title>Blog of Shaun McCran - Architecting robust, elegant technical and business solutions - Flex</title>
			<link>http://www.mccran.co.uk/index.cfm</link>
			<description>I write about Architecture and Design, Architectural patterns, Architectural Principles and Architectural policies. This includes TOGAF, Zachman, Business Architecture, SOA and Process and tools such as the IBM Rational software and Adobe products. I also write about my previous life as a mobile and web developer.</description>
			<language>en-gb</language>
			<pubDate>Tue, 09 Jun 2026 06:58:08 -0000</pubDate>
			<lastBuildDate>Wed, 24 Oct 2012 07:28:00 -0000</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>shaun@mccran.co.uk</managingEditor>
			<webMaster>shaun@mccran.co.uk</webMaster>
			<itunes:subtitle></itunes:subtitle>
			<itunes:summary></itunes:summary>
			<itunes:category text="Technology" />
			<itunes:category text="Technology">
				<itunes:category text="Podcasting" />
			</itunes:category>
			<itunes:category text="Technology">
				<itunes:category text="Tech News" />
			</itunes:category>
			<itunes:keywords></itunes:keywords>
			<itunes:author></itunes:author>
			<itunes:owner>
				<itunes:email>shaun@mccran.co.uk</itunes:email>
				<itunes:name></itunes:name>
			</itunes:owner>
			
			<itunes:explicit>no</itunes:explicit>
			
			
			
			
			
			<item>
				<title>XML Whitespace is evil and should be punished</title>
				<link>http://www.mccran.co.uk/index.cfm/2012/10/24/XML-Whitespace-is-evil-and-should-be-punished</link>
				<description>
				
				I&apos;ve spent a bit of time recently working on a flash based reporting website. The project is all pretty standard architecture for a flash website, but there has been a persistent issue about loading times and poor user experience.

After having a bit of digging around behind the scenes it appeared as though the flash SWF file was streaming a configuration XML file in the background. This isn&apos;t a great idea at the best of times but in this case the file was 147k lines long and weighed in at 22.5mb. So this accounted for a stack of loading time when the flash app loads up.

After downloading the XML file and browsing through it in Eclipse my first impression is that there was a ton of whitespace in it. After running a quick &apos;find and replace&apos; on any double space characters (to avoid removing spaces in legitimate text strings) and re-saving the file was down to 3.2mb.

So let this be a warning to anyone loading up machine-to-machine text files. Squeeze them down, don&apos;t include whitespace, your Apps don&apos;t care about it, the file doesn&apos;t need to be human readable, all you are doing is using up network bandwidth.

I won&apos;t even get into the risks involved in allowing your config files to be downloaded by people here, that&apos;s a whole different issue!
				
				</description>
				
				
				<category>Best practices</category>
				
				<category>Flex</category>
				
				<pubDate>Wed, 24 Oct 2012 07:28:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2012/10/24/XML-Whitespace-is-evil-and-should-be-punished</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Opening a new window from a flex / AIR application</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/6/12/Opening-a-new-window-from-a-flex--AIR-application</link>
				<description>
				
				I was sure I had done this before, somewhere but I couldn&apos;t find the code anywhere. So I&apos;ve knocked together a really quick and simple example.

I want to be able to open a new site in a pop up from an AIR application. To do this I need to use the &apos;urlRequest&apos; function to create a url request. Then insert that into a &apos;navigateToURL&apos; method, specifying that you want a new window &apos;_new&apos;.

Here is the complete example.

&lt;code&gt;

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;absolute&quot;&gt;

&lt;mx:Script&gt;
	&lt;![CDATA[

	  public function goToUrl(link:String):void
	  {
		var urlRequest:URLRequest = new URLRequest(&apos;http://&apos; + link);
		navigateToURL(urlRequest, &quot;_new&quot;);
	  }   
		
	]]&gt;
&lt;/mx:Script&gt;
	
	&lt;mx:Canvas x=&quot;10&quot; y=&quot;10&quot; width=&quot;321&quot; height=&quot;146&quot; backgroundColor=&quot;#FFFFFF&quot;&gt;
		&lt;mx:Form x=&quot;10&quot; y=&quot;52&quot;&gt;
			&lt;mx:FormItem label=&quot;URL&quot;&gt;
				&lt;mx:TextInput id=&quot;urlTxt&quot;/&gt;
			&lt;/mx:FormItem&gt;
		&lt;/mx:Form&gt;
		&lt;mx:Button x=&quot;10&quot; y=&quot;114&quot; label=&quot;Go to&quot; click=&quot;goToUrl(urlTxt.text)&quot;/&gt;
		&lt;mx:Label x=&quot;10&quot; y=&quot;10&quot; text=&quot;New Window test&quot; /&gt;
	&lt;/mx:Canvas&gt;
	
&lt;/mx:Application&gt;

&lt;/code&gt;

Works like this.

&lt;a href=&quot;http://www.mccran.co.uk/newWindowTest.html&quot; target=&quot;_newwin&quot;&gt;View demo&lt;/a&gt;.
				
				</description>
				
				
				<category>AIR</category>
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Fri, 12 Jun 2009 14:34:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/6/12/Opening-a-new-window-from-a-flex--AIR-application</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Flex Currency Formatter Example</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/4/5/Flex-Currency-Formatter-Example</link>
				<description>
				
				Whilst developing a new Flex shopping cart I came across an issue in dealing with the formatting of currencies for the payment system. The previous version of the shopping cart had preformatted values stored in the actual database, so I was simply displaying them in the Flex front end.

In this version there is the specific requirement that it is able to handle a multi currency configuration. So I thought I&apos;d dig out the documentation on the Flex currency Formatter.

Firstly create a CurrencyFormatter object, and specify the currency symbol, and any other formatting parameters that you require.

Next create a NumberValidator, as this will validate our entered value as a numeric value, we don&apos;t need to try and re-format alpha numeric values.

Then create a form to run the test validation against. I often find it easier to build a test mechanism at the same time. Below is a simple submission form, in the form we just enter the value, click the Button, which fires the Format() function.

&lt;code&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;!-- Simple example to demonstrate the CurrencyFormatter. --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;absolute&quot;&gt;

    &lt;mx:CurrencyFormatter id=&quot;ukFormatter&quot; precision=&quot;2&quot; 
        currencySymbol=&quot;£&quot; decimalSeparatorFrom=&quot;.&quot;
        decimalSeparatorTo=&quot;.&quot; useNegativeSign=&quot;true&quot; 
        useThousandsSeparator=&quot;true&quot; alignSymbol=&quot;left&quot;/&gt;
 
    &lt;mx:NumberValidator id=&quot;numVal&quot; source=&quot;{priceUK}&quot; property=&quot;text&quot; 
        allowNegative=&quot;true&quot; domain=&quot;real&quot;/&gt;
 
    &lt;mx:Panel title=&quot;CurrencyFormatter Example&quot; width=&quot;75%&quot; height=&quot;75%&quot; 
        paddingTop=&quot;10&quot; paddingLeft=&quot;10&quot; paddingRight=&quot;10&quot; paddingBottom=&quot;10&quot;&gt;
 
        &lt;mx:Form&gt;
            &lt;mx:FormItem label=&quot;Enter U.K. dollar amount:&quot;&gt;
                &lt;mx:TextInput id=&quot;priceUK&quot; text=&quot;&quot; width=&quot;50%&quot;/&gt;
            &lt;/mx:FormItem&gt;
 
            &lt;mx:FormItem label=&quot;Formatted amount: &quot;&gt;
                &lt;mx:TextInput id=&quot;formattedUKPrice&quot; text=&quot;&quot; width=&quot;50%&quot; editable=&quot;false&quot;/&gt;
            &lt;/mx:FormItem&gt;
 
            &lt;mx:FormItem&gt;
                &lt;mx:Button label=&quot;Validate and Format&quot; click=&quot;Format();&quot;/&gt;
            &lt;/mx:FormItem&gt;
        &lt;/mx:Form&gt;
 
    &lt;/mx:Panel&gt;
 
&lt;/mx:Application&gt;
&lt;/code&gt;

The Format() function checks that the value is numeric, and applies the CurrencyFormatter object to the value. Then we simply assign the newly formatted value back to our Text field in the form.

&lt;code&gt;


    &lt;mx:Script&gt;
        &lt;![CDATA[
 
              import mx.events.ValidationResultEvent;            
              private var vResult:ValidationResultEvent;
            
              // Event handler to validate and format input.
              private function Format():void {
              
                     vResult = numVal.validate();
 
                    if (vResult.type==ValidationResultEvent.VALID) {
                        var temp:Number=Number(priceUK.text); 
                        formattedUKPrice.text= ukFormatter.format(temp);
                    }
                    
                    else {
                       formattedUKPrice.text=&quot;&quot;;
                    }
              }
        ]]&gt;
    &lt;/mx:Script&gt;
&lt;/code&gt;




&lt;img src=&quot;http://www.mccran.co.uk/images/images//currencyFormatter.jpg&quot;&gt;
				
				</description>
				
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Sun, 05 Apr 2009 23:08:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/4/5/Flex-Currency-Formatter-Example</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>AIR Phone Book application - Part 3 (Full code)</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/4/3/AIR-Phone-Book-application--Part-3-Full-code</link>
				<description>
				
				Below is the full code in one run for the PhoneBook AIR application.

&lt;code&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:WindowedApplication xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;absolute&quot; initialize=&quot;init()&quot; 
	height=&quot;280&quot; width=&quot;294&quot; horizontalAlign=&quot;center&quot; verticalAlign=&quot;middle&quot; showFlexChrome=&quot;false&quot;&gt;

&lt;mx:Script&gt;
	&lt;![CDATA[
	  
	  import mx.controls.Alert;
      import mx.collections.*;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.events.ResultEvent;
      import mx.collections.ArrayCollection;

	  [Bindable]
	  private var loadedData:ArrayCollection;
      
      public function init():void
      {
		// start the move listener
		moveListener()
      	// get the remote data
      	getData()
      }
      
      public function moveListener():void
      {
		// mover event
		outerCanvas.addEventListener( MouseEvent.MOUSE_DOWN, moveWindow );  	
      }     
             
      public function getData():void
      {
      	popData.getData();
      }

	  public function moveWindow( event:MouseEvent ):void
	  {
		var str:String = event.target.valueOf();

		  // if its a datagrid then don&apos;t do the move
		  if ( str.search(&quot;displayPeople&quot;) &gt;= 1)
		  {
		  	// Do nothing
		  }
		  else
		  {
		  	stage.nativeWindow.startMove();
		  }
	  }
	  
	  public function onMinimize():void
	  {
	  	stage.nativeWindow.minimize();
	  }
	  
	  public function onClose():void
	  {
	  	stage.nativeWindow.close();
	  }    

	  public function resultsHandler(event:ResultEvent):void
	  {
		// trace(event.result)
		displayPeople.dataProvider = popData.getData.lastResult
	  } 

	  public function faultHandler(event:FaultEvent):void
	  {
		Alert.show(&quot;Error: &quot; + event.fault.faultString, &quot;Application Error&quot;);
	  }

	  public function changeImage(img:String):void
	  {
	  	userImage.visible = true
	  	userImage.source = &quot;http://www.url.co.uk/wld/phonebook/&quot; + img
	  }   

   ]]&gt;
&lt;/mx:Script&gt;

&lt;mx:Style&gt;
	.header {color: #70c7f1;}
	.greyHeader {color: #777879;}
	.controls {color: #000000; font-size: 13pt;}
&lt;/mx:Style&gt;

 	&lt;mx:WebService id=&quot;popData&quot; wsdl=&quot;http://www.url.co.uk/wld/services/phoneBook.cfc?wsdl&quot; showBusyCursor=&quot;true&quot; useProxy=&quot;false&quot;&gt;
        &lt;mx:operation name=&quot;getData&quot; fault=&quot;faultHandler(event)&quot; result=&quot;resultsHandler(event)&quot; /&gt;
    &lt;/mx:WebService&gt;

 	&lt;mx:Fade id=&quot;fadeOut&quot; duration=&quot;1.0&quot; alphaFrom=&quot;1.0&quot; alphaTo=&quot;0.0&quot;/&gt;
    &lt;mx:Fade id=&quot;fadeIn&quot; duration=&quot;2000&quot; alphaFrom=&quot;0.0&quot; alphaTo=&quot;1.0&quot;/&gt;

	&lt;mx:Canvas id=&quot;outerCanvas&quot; x=&quot;0&quot; y=&quot;0&quot; width=&quot;220&quot; height=&quot;240&quot; backgroundColor=&quot;#70c7f1&quot; borderStyle=&quot;solid&quot; cornerRadius=&quot;25&quot; borderThickness=&quot;0&quot;&gt;
	
		&lt;mx:Canvas id=&quot;innerCanvas&quot; x=&quot;10&quot; y=&quot;22&quot; width=&quot;200&quot; height=&quot;210&quot; backgroundColor=&quot;#FFFFFF&quot; borderStyle=&quot;solid&quot; cornerRadius=&quot;25&quot; borderThickness=&quot;0&quot;&gt;
			
			&lt;mx:Label x=&quot;10&quot; y=&quot;10&quot; text=&quot;White label&quot; id=&quot;header&quot; styleName=&quot;header&quot; fontWeight=&quot;bold&quot;/&gt;
			&lt;mx:Label x=&quot;78&quot; y=&quot;10&quot; text=&quot;Dating PhoneBook&quot; styleName=&quot;greyHeader&quot; fontWeight=&quot;bold&quot;/&gt;
			&lt;mx:DataGrid id=&quot;displayPeople&quot; x=&quot;10&quot; y=&quot;32&quot; width=&quot;180&quot; height=&quot;108&quot; itemClick=&quot;changeImage(displayPeople.selectedItem.IMAGE)&quot;&gt;
				&lt;mx:columns&gt;
					&lt;mx:DataGridColumn headerText=&quot;Name&quot; width=&quot;140&quot; dataField=&quot;NAME&quot;/&gt;
					&lt;mx:DataGridColumn headerText=&quot;No.&quot; width=&quot;40&quot; dataField=&quot;NO&quot;/&gt;
					&lt;mx:DataGridColumn headerText=&quot;Img&quot; width=&quot;40&quot; dataField=&quot;IMAGE&quot; visible=&quot;false&quot;/&gt;
				&lt;/mx:columns&gt;
			&lt;/mx:DataGrid&gt;
			&lt;mx:Image x=&quot;138&quot; y=&quot;150&quot; source=&quot;@Embed(source=&apos;wldLogoTiny.png&apos;)&quot; /&gt;
			&lt;mx:Image x=&quot;25&quot; y=&quot;144&quot; toolTip=&quot;{displayPeople.selectedItem.NAME}&quot; id=&quot;userImage&quot; visible=&quot;true&quot; showEffect=&quot;{fadeIn}&quot; /&gt;
		&lt;/mx:Canvas&gt;
		&lt;mx:Label text=&quot;_&quot; styleName=&quot;controls&quot; toolTip=&quot;Minimize&quot; x=&quot;173&quot; y=&quot;-2&quot; click=&quot;onMinimize()&quot; /&gt;
		&lt;mx:Label text=&quot;X&quot; styleName=&quot;controls&quot; toolTip=&quot;Close&quot; x=&quot;184&quot; y=&quot;1&quot; click=&quot;onClose()&quot; /&gt;

	&lt;/mx:Canvas&gt;

&lt;/mx:WindowedApplication&gt;
&lt;/code&gt;

&lt;img src=&quot;http://www.mccran.co.uk/images/images//phonebookScreenShot.jpg&quot; alt=&quot;PhoneBook screen shot&quot;&gt;
				
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>AIR</category>
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Fri, 03 Apr 2009 15:17:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/4/3/AIR-Phone-Book-application--Part-3-Full-code</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>AIR Phone Book application - Part 2 (Functions and WebService)</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/4/3/AIR-Phone-Book-application--Part-2-Functions-and-WebService</link>
				<description>
				
				As our application starts I want to fire the request for data, so we call an init() method on initialization. Also I have turned the flex chrome off here with &apos;showFlexChrome=&quot;false&quot;&apos;.

&lt;code&gt;
&lt;mx:WindowedApplication xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;absolute&quot; initialize=&quot;init()&quot; 
	height=&quot;280&quot; width=&quot;294&quot; horizontalAlign=&quot;center&quot; verticalAlign=&quot;middle&quot; showFlexChrome=&quot;false&quot;&gt;
&lt;/code

The init() method calls an event listener that controls the window movement (Drag and drop) and makes a call to getData().

&lt;code&gt;
	  import mx.controls.Alert;
      import mx.collections.*;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.events.ResultEvent;
      import mx.collections.ArrayCollection;

	  [Bindable]
	  private var loadedData:ArrayCollection;
      public function init():void
      {
		// start the move listener
		moveListener()
      	// get the remote data
      	getData()
      }
&lt;/code&gt;

The moveListener() method adds a listener to the outerCanvas element which forms the application &apos;border&apos;.  When this event is fired it calls moveWindow.

The getData() function calls the webservice, and specifies which method to call.

&lt;code&gt;
     public function moveListener():void
      {
		// mover event
		outerCanvas.addEventListener( MouseEvent.MOUSE_DOWN, moveWindow );  	
      }     
             
      public function getData():void
      {
      	popData.getData();
      }
	  public function moveWindow( event:MouseEvent ):void
	  {
		var str:String = event.target.valueOf();

		  // if its a datagrid then don&apos;t do the move
		  if ( str.search(&quot;displayPeople&quot;) &gt;= 1)
		  {
		  	// Do nothing
		  }
		  else
		  {
		  	stage.nativeWindow.startMove();
		  }
	  }
&lt;/code&gt;

The moveWindow function also contains a check to see if the datagrid was the event target, as this was interfering with the functionality of the Datagrid. It would be interesting to see if anyone else has a more elegant solution to this, rather than a specific element check.

To populate our datagrid we need to use a data provider. In FLEX applications I usually use the RemoteObject function, but for AIR I&apos;ve been using the WebService tag.

&lt;code&gt;
	&lt;mx:WebService id=&quot;popData&quot; wsdl=&quot;http://url/wld/services/phoneBook.cfc?wsdl&quot; showBusyCursor=&quot;true&quot; useProxy=&quot;false&quot;&gt;
        &lt;mx:operation name=&quot;getData&quot; fault=&quot;faultHandler(event)&quot; result=&quot;resultsHandler(event)&quot; /&gt;
    &lt;/mx:WebService&gt;

&lt;/code&gt;

The final two &apos;chrome&apos; functions we need are the minimize and close functions. I will detail handling custom chrome in another article.

&lt;code&gt;
  
	  public function onMinimize():void
	  {
	  	stage.nativeWindow.minimize();
	  }
	  
	  public function onClose():void
	  {
	  	stage.nativeWindow.close();
	  }    
&lt;/code&gt;

Our WebService is referencing two functions. A results handler and a fault handler.

&lt;code&gt;

	  public function resultsHandler(event:ResultEvent):void
	  {
		// trace(event.result)
		displayPeople.dataProvider = popData.getData.lastResult
	  } 

	  public function faultHandler(event:FaultEvent):void
	  {
		Alert.show(&quot;Error: &quot; + event.fault.faultString, &quot;Application Error&quot;);
	  }

&lt;/code&gt;

The resultsHandler() simply assigns the datagrids dataprovider as the result of the WebService call. By adding DataGridColumn&apos;s to the datagrid with the right naming convention our results from the returned query object will map directly to our datagrid.

The faultHandler() function simply Alerts a user to a fault event.

Lastly I have a function that assigns the image source dynamically based on the click event in the datagrid.

&lt;code&gt;
	  public function changeImage(img:String):void
	  {
	  	userImage.visible = true
	  	userImage.source = &quot;http://url/wld/phonebook/&quot; + img
	  }   
&lt;/code&gt;

So that completes the Phone Book AIR application. There are one or two tweaks I&apos;d like to make in the image handling, but otherwise its exactly the spec I had in mind.

You can view the full code &lt;a href=&quot;http://www.mccran.co.uk/index.cfm/2009/4/3/AIR-Phone-Book-application--Part-3-Full-code&quot;&gt;here&lt;/a&gt;.
				
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>AIR</category>
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Fri, 03 Apr 2009 15:13:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/4/3/AIR-Phone-Book-application--Part-2-Functions-and-WebService</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Adobe AIR Web Service Hello World test application</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/4/2/Adobe-AIR-Web-Service-Hello-World-test-application</link>
				<description>
				
				I&apos;ve recently been looking at putting together some AIR applications. I&apos;ve used FLEX for a few years now, and have only just come up with some &lt;i&gt;useful&lt;/i&gt; AIR ideas, so I thought I&apos;d build an application or two.

Usually I would use flash remoting, but I haven&apos;t spent too much time investigating how this works in AIR, so I&apos;ve opted for the old school Web Service.

In the middle of my newest AIR application I stumbled upon an issue. No matter what I did I was receiving a &apos;HTTP Error&apos; response from my Web Service. After stumbling around in the dark for a while tweaking code to no avail, I decided to write the most basic Web Service I could think of.

So here is &apos;Hello World&apos;, as a Web Service call from AIR.

Firstly create a call to your Web Service. In this case it was a local file. Point the wsdl variable at the fully qualified path to your service. I am using a coldFusion back end, so it is a CFC. This is also where you specify the fault handler and result handlers. You can add as many &apos;operation&apos; methods here as you want, that way you address specific functions in your service individually.

&lt;code&gt;
 	&lt;mx:WebService id=&quot;getMessages&quot; wsdl=&quot;http://192.168.XX.XXX/root/services/message.cfc?wsdl&quot; showBusyCursor=&quot;true&quot;&gt;
        &lt;mx:operation name=&quot;sayHello&quot; fault=&quot;faultHandler(event)&quot; result=&quot;resultsHandler(event)&quot; /&gt;
    &lt;/mx:WebService&gt;
 	&lt;mx:Button x=&quot;10&quot; y=&quot;10&quot; label=&quot;Click me&quot; click=&quot;getData()&quot;/&gt;
	
&lt;/mx:WindowedApplication&gt;
&lt;/code&gt;

I&apos;ve also added a button that will call a function to action the service call.

Next we will add the functions.

&lt;code&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:WindowedApplication xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;absolute&quot;&gt;

&lt;mx:Script&gt;
	&lt;![CDATA[
		import mx.rpc.events.ResultEvent;
		import mx.rpc.events.FaultEvent;
		import mx.controls.Alert;
		
      private function getData():void{
      	getMessages.sayHello();
      	
      }

	  private function faultHandler(event:FaultEvent):void
	  {
		Alert.show(&quot;Error: &quot; + event.fault.faultString, &quot;Application Error&quot;);
	  }

	  private function resultsHandler(event:ResultEvent):void
	  {
		Alert.show(String(event.result))
		
	  } 
	
	]]&gt;
&lt;/mx:Script&gt;
&lt;/code&gt;

A getter function, that will actually send the Service request, a fault handler that will simply Alert the user to a fault event, and a result handler that Alerts the user to whatever message is returned from the Web Service.

&lt;h3&gt;The CFC&lt;/h3&gt;

The CFC service is a simply object to return a string. Just make sure that your &apos;Access&apos; is set to remote.

&lt;code&gt;
&lt;cfcomponent displayname=&quot;message&quot;&gt;


	&lt;cffunction name=&quot;sayHello&quot; displayname=&quot;sayHello&quot; hint=&quot;it says hello&quot; access=&quot;remote&quot; output=&quot;true&quot; returntype=&quot;String&quot;&gt;
		
		&lt;cfset var message = &quot;Hello world&quot;&gt;
		
		&lt;cfreturn message/&gt;
	&lt;/cffunction&gt;

&lt;/cfcomponent&gt;
&lt;/code&gt;

So we end out with:








&lt;img src=&quot;http://www.mccran.co.uk/images/images//helloWorld.jpg&quot;&gt;
				
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>Coldfusion</category>
				
				<category>AIR</category>
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Thu, 02 Apr 2009 10:55:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/4/2/Adobe-AIR-Web-Service-Hello-World-test-application</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Adobe releases Tour-de-Flex as Eclipse plugin</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/4/1/Adobe-releases-TourdeFlex-as-Eclipse-plugin</link>
				<description>
				
				I was directed to the Adobe Developer Connection site by a colleague the other day, and told to go look at &apos;&lt;a href=http://www.adobe.com/devnet/flex/tourdeflex/ target=&quot;new_win&quot;&gt;Tour-de-Flex&lt;/a&gt;&apos;.

&lt;iframe width=&quot;216&quot; height=&quot;182&quot; frameborder=0 scrolling=&quot;no&quot; src=&quot;http://tourdeflex.adobe.com/badge/&quot;&gt;&lt;/iframe&gt;

Its an AIR/Web application that hosts a whole range of example FLEX and AIR resources. 

Its also available as a handy eclipse plugin, if you are that way inclined :-)

I&apos;ve had a brief look around it, and it looks pretty good, very handy having code examples and themes right there on your desktop. 

Also gave me some interesting trains of thought of the next AIR application I have in mind....
				
				</description>
				
				
				<category>Eclipse</category>
				
				<category>AIR</category>
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Wed, 01 Apr 2009 11:00:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/4/1/Adobe-releases-TourdeFlex-as-Eclipse-plugin</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Adobe brings AIR to Linux</title>
				<link>http://www.mccran.co.uk/index.cfm/2008/12/19/Adobe-brings-AIR-to-Linux</link>
				<description>
				
				Adobe delivers AIR to Linux platforms!

Adobe finally brings the AIR SDK to a variety of linux platforms. Handy if your home development network is Ubuntu based.

Full article here:

&lt;a href=&quot;http://www.theregister.co.uk/2008/12/18/adobe_air_linux/&quot; target=&quot;new_win&quot;&gt;
&lt;img src=&quot;http://www.mccran.co.uk/images/images//adobe_air.png&quot; border=&quot;0&quot;&gt;&lt;/a&gt;
				
				</description>
				
				
				<category>AIR</category>
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Fri, 19 Dec 2008 15:30:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2008/12/19/Adobe-brings-AIR-to-Linux</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Returning useful error messages from CFC&apos;s in Flex</title>
				<link>http://www.mccran.co.uk/index.cfm/2008/12/1/Returning-useful-error-messages-from-CFCs-in-Flex</link>
				<description>
				
				One thing I&apos;ve learnt from my flex to CFC tomfoolery is that sometimes flex doesn&apos;t diplay very good error messages from CFC&apos;s. This is no fault of flex, but more usually a problem with the interface between it, and CF, as most of the unfriendly error messages you get are http error strings, which usually get truncated as they are raw code, so you don&apos;t get to see the problem then either.

So you need more elegant error handling in your CFC&apos;s. (or whatever back end your using)

Here is a complete script as an example, we will go through it line by line:

&lt;code&gt;
&lt;cfcomponent displayname=&quot;Data Object&quot; hint=&quot;Generic data object&quot; output=&quot;false&quot;&gt;


	&lt;cffunction name=&quot;selectRecords&quot; hint=&quot;Returns a query object based on an id&quot; access=&quot;public&quot; output=&quot;false&quot; returntype=&quot;Any&quot;&gt;
		&lt;cfargument name=&quot;id&quot; required=&quot;true&quot; type=&quot;String&quot; hint=&quot;An id to use in the query below&quot;&gt;

			&lt;cfset var message = &quot;&quot;&gt;

			&lt;!--- TRY the transaction below, throw a catch message ---&gt;
			&lt;cftry&gt;
	
				&lt;cfif NOT isNumeric(arguments.id)&gt;
					&lt;cfset message = &quot;Id was not a number&quot;&gt;
				&lt;/cfif&gt;
	
				&lt;cfquery datasource=&quot;#application.dsn#&quot; name=&quot;qGetRecordById&quot;&gt;
					SELECT id, name, age, sex, telephone, mobile, address, postcode, county, country
					FROM memberTable
					Where id = #arguments.id#
				&lt;/cfquery&gt;
	
			&lt;cfcatch&gt;
				&lt;cfthrow message=&quot;cfcatch.message&quot;&gt;

							&lt;cfreturn message&gt;
			&lt;/cfcatch&gt;
			
			&lt;/cftry&gt;
		
		&lt;cfreturn qGetRecordById /&gt;
	&lt;/cffunction&gt;
&lt;/cfcomponent&gt;
&lt;/code&gt;

So its a normal component, with one function, it accepts an &apos;ID&apos; and performs a query, and returns it.

I am setting a local variable at the top, &apos;message&apos; that will only be created and used inside the scope of the CFC. Then we will &apos;TRY&apos; and do our transaction. At this point I&apos;m wrapping everything in the cftry tag so as to encapsulate any possible code errors or logic faults.

Any logic I have here will replace the value of &apos;message&apos; if proven to be false, and return that message rather than the query object I was expecting.

But you&apos;ll notice the lines:
&lt;code&gt;
			&lt;cfcatch&gt;
				&lt;cfthrow message=&quot;cfcatch.message&quot;&gt;

				&lt;cfreturn message&gt;
			&lt;/cfcatch&gt;
&lt;/code&gt;

This will catch any errors from the try block, and throw them to flex. In this way flex receives the message in the throw command, not a http response message when the CFC breaks.

This is obviously a Coldfusion - CFC specific example, but I&apos;ve seen very similar error trapping in php, working in exactly the same way, so it really doesn&apos;t matter what back end your using with flex.
				
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>Coldfusion</category>
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Mon, 01 Dec 2008 14:30:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2008/12/1/Returning-useful-error-messages-from-CFCs-in-Flex</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Be careful using URL FlashVars!</title>
				<link>http://www.mccran.co.uk/index.cfm/2008/10/26/Be-careful-using-URL-FlashVars</link>
				<description>
				
				A while ago I subscribed to an online magazine. Its a bit laddish, but it has the odd interesting article, and its done in flash/flex.

The most recent article arrived in my in-box the other day, and one of the pages was an advert for the new film &apos;eagle eye&apos; rather unfortunately they had passed in your subscription name value as a flashVar in the URL scope.

This is probably one of the easiest ways to pass variables into flex, but also the most unsecure, and easily changed, as per the screen shot below. Luckily in this case it was just a display variable, but what about if this was a query param? or a value for a piece of data being sent back to a server?

There are many other ways of passing variables into flex apps, I&apos;d go for using a properties file. Have your flex look for a server side XML definitions file on &quot;creationComplete&quot;. Or edit your Embed/Object code, whilst still not ideal its far better than a url variable!

The magazine:&lt;br/&gt;
&lt;a href=&quot;http://www.monkeymag.co.uk/&quot; target=&quot;new&quot;&gt;http://www.monkeymag.co.uk/&lt;/a&gt;

&lt;img src=&quot;http://www.mccran.co.uk/images/images//flashvars.jpg&quot;&gt;
				
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>Best practices</category>
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Sun, 26 Oct 2008 18:40:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2008/10/26/Be-careful-using-URL-FlashVars</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Flex - Coldfusion Remoting, passing an Object usefully</title>
				<link>http://www.mccran.co.uk/index.cfm/2008/7/1/Flex--Coldfusion-Remoting-passing-an-Object-usefully</link>
				<description>
				
				Ever noticed that with the increase in scale of a Flex application, the amount of data that you pass around seems to grow exponentially? Well I was fed up with passing multiple values back and forth from CF to flex, so after some digging here&apos;s the first article in using objects in remoting.
				 [More]
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>Coldfusion</category>
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Tue, 01 Jul 2008 17:30:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2008/7/1/Flex--Coldfusion-Remoting-passing-an-Object-usefully</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>ColdFusion - Flex remoting struct() case sensitivity</title>
				<link>http://www.mccran.co.uk/index.cfm/2008/7/1/ColdFusion--Flex-remoting-struct-case-sensitivity</link>
				<description>
				
				One of the more frequent data Objects that I pass from CF to Flex is the structure. I recently stumbled upon a case sensitivity issue in flex, that can be solved in CF with a slight change in code.
				 [More]
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>AIR</category>
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Tue, 01 Jul 2008 12:05:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2008/7/1/ColdFusion--Flex-remoting-struct-case-sensitivity</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Method for populating a flex combo box from cfc</title>
				<link>http://www.mccran.co.uk/index.cfm/2008/6/24/Method-for-populating-a-flex-combo-box-from-cfc</link>
				<description>
				
				Many of the flex form elements can be populated directly from the data output from a coldfusion cfc, as long as you get the format right!

Here&apos;s the best way I&apos;ve found to painlessly populate a combo box in flex.
				 [More]
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>Coldfusion</category>
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Tue, 24 Jun 2008 10:09:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2008/6/24/Method-for-populating-a-flex-combo-box-from-cfc</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Strongly typing data between flex and coldfusion</title>
				<link>http://www.mccran.co.uk/index.cfm/2008/6/23/Strongly-typing-data-between-flex-and-coldfusion</link>
				<description>
				
				As part of an ongoing series of working out the best ways of passing data around from coldfusion to flex (and back again) I&apos;m looking at the different formats of passing data into flex.

I&apos;ve heard that you can &quot;strongly type&quot; the arguments and method names etc, and that allows for much easier passing of data back and forth.
				 [More]
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>Coldfusion</category>
				
				<category>Flex</category>
				
				<pubDate>Mon, 23 Jun 2008 14:15:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2008/6/23/Strongly-typing-data-between-flex-and-coldfusion</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Flex Pop-ups, and disabling/enabling the parent application</title>
				<link>http://www.mccran.co.uk/index.cfm/2008/6/13/Flex-Popups-and-disabling-the-parent-application</link>
				<description>
				
				I recently needed to create a pop up window in flex, and knew that I wanted to replicate much of the functionality of the &apos;Alert&apos; method, IE graying out the background.
				 [More]
				</description>
				
				
				<category>RIA</category>
				
				<category>Flex</category>
				
				<pubDate>Fri, 13 Jun 2008 14:12:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2008/6/13/Flex-Popups-and-disabling-the-parent-application</guid>
				
				
			</item>
			
		 	
			</channel></rss>