<?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 Remoting</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:57:38 -0000</pubDate>
			<lastBuildDate>Fri, 23 Jul 2010 15:24: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>Flex webservices security error accessing url</title>
				<link>http://www.mccran.co.uk/index.cfm/2010/7/23/Flex-webservices-security-error-accessing-url</link>
				<description>
				
				I&apos;ve been working with some client side flash developers recently and we came across an unusual error that was being thrown in a Flex application when we were sending a webservice request to a Coldfusion server.

The error was &quot;Security error accessing URL&quot;. I thought I&apos;d overcome this a long time ago by using the cross-domain.xml file to allow server access to services.

It appears that there is a security issue with Flash 9 that requires the following line to be added to the CrossDomain.xml file:

&lt;code&gt;
&lt;allow-http-request-headers-from domain=&quot;*&quot; headers=&quot;SOAPAction&quot;/&gt;
&lt;/code&gt;

I&apos;m guessing that it is enabling access for SOAP requests to any remote services on that server.
				
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>Security</category>
				
				<category>Development</category>
				
				<pubDate>Fri, 23 Jul 2010 15:24:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2010/7/23/Flex-webservices-security-error-accessing-url</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>ColdFusion structures and case sensitivity examples</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/10/13/ColdFusion-structures-and-case-sensitivity-examples</link>
				<description>
				
				Having been using Flex a little more recently I stumbled upon an old issue that I had previously addressed, but it had become second nature, and so I had forgotten about having to learn a workaround in the past. Passing objects from ColdFusion to Flex can be tricky at times, especially as ColdFusion is generally not case sensitive, but Flex is, and this can lead to problems.

I had previously found that how you build your Structure will have an impact the case of the keys. Example one is a Structure built using the traditional dot notation, in a CF 7 and below method:

&lt;code&gt;
&lt;cfscript&gt;
	newStruct = structNew();
	newStruct.starter = &quot;Prawn Salad&quot;;
	newStruct.maincourse = &quot;Roast Chicken&quot;;
	newStruct.desert = &quot;Apple Pie&quot;;
&lt;/cfscript&gt;

&lt;cfdump var=&quot;#newStruct#&quot; label=&quot;Dot notation&quot;&gt;

&lt;/code&gt;

&lt;img src=&quot;http://www.mccran.co.uk/images/struct_dot.gif&quot; /&gt;

This is the older way of building a Structure, notice how all the keys are uppercase.

The second example is very similar, except that it is using associative array notation, IE brackets to denote the key values, rather than dot notation.

&lt;code&gt;
&lt;cfscript&gt;
	newStruct = structNew();
	newStruct[&quot;starter&quot;] = &quot;Prawn Salad&quot;;
	newStruct[&quot;maincourse&quot;] = &quot;Roast Chicken&quot;;
	newStruct[&quot;desert&quot;] = &quot;Apple Pie&quot;;
&lt;/cfscript&gt;

&lt;cfdump var=&quot;#newStruct#&quot; label=&quot;Struct notation&quot;&gt;

&lt;/code&gt;

&lt;img src=&quot;http://www.mccran.co.uk/images/struct_notation.gif&quot; /&gt;

Since I originally looked at this ColdFusion 8 (and now 9!) have been released. ColdFusion 8 introduced a new way of creating structures, what casing does this use?

&lt;code&gt;
&lt;cfset newStruct = {
	starter = &quot;Prawn Salad&quot;,
	maincourse = &quot;Roast Chicken&quot;,
	desert = &quot;Apple Pie&quot;
} /&gt;

&lt;cfdump var=&quot;#newStruct#&quot; label=&quot;CF 8 method&quot;&gt;

&lt;/code&gt;

&lt;img src=&quot;http://www.mccran.co.uk/images/struct_cf8.gif&quot; /&gt;

It also creates an uppercase structure.  I haven&apos;t really played around with this method enough to see if there is another way of creating a lowercase structure, so for now I&apos;ll be sticking to the older associative array method of creating my structures. That way they are easily transferred as a Flex object.
				
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>Coldfusion</category>
				
				<pubDate>Tue, 13 Oct 2009 12:24:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/10/13/ColdFusion-structures-and-case-sensitivity-examples</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Example of inserting a Struct() into a database using keys</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/8/26/Example-of-inserting-a-Struct-into-a-database-using-keys</link>
				<description>
				
				A while ago a colleague and I were working on a timesheet application in Flex. The idea was that you could commit a custom timebar object, generated in flex, and it would update the dataset in the back end using the ColdFusion flex gateway. 

I came across the code recently, and decided to tidy it up a bit, and make the query dynamic, based on the Struct contents. The obvious limitation to this is that your Struct and your database schema have to match exactly.

I won&apos;t go into the Flex application here, but I&apos;ve emulated its input arguments here with a pre-populated structure.

&lt;code&gt;
&lt;cfscript&gt;
      timesheetTask = StructNew();
      StructInsert(timesheetTask, &quot;employeeid&quot;, &apos;36&apos;);
      StructInsert(timesheetTask, &quot;timesheetDT&quot;, &apos;0&apos;);
      StructInsert(timesheetTask, &quot;projectid&quot;, &apos;6&apos;);
      StructInsert(timesheetTask, &quot;weekid&quot;, &apos;25&apos;);
      StructInsert(timesheetTask, &quot;taskid&quot;, &apos;39&apos;);
      StructInsert(timesheetTask, &quot;hours&quot;, &apos;8&apos;);
      StructInsert(timesheetTask, &quot;comment&quot;, &apos;Comments for this task live here&apos;);
      StructInsert(timesheetTask, &quot;szStatus&quot;, &apos;1&apos;);
      StructInsert(timesheetTask, &quot;iFirstLineApproval&quot;, &apos;23&apos;);
      StructInsert(timesheetTask, &quot;iSecondLineApproval&quot;, &apos;34&apos;);
      StructInsert(timesheetTask, &quot;iCurrentApprover&quot;, &apos;&apos;);
      StructInsert(timesheetTask, &quot;szRejectReason&quot;, &apos;&apos;);
      StructInsert(timesheetTask, &quot;szDescription&quot;, &apos;&apos;);
 
      updateTimesheet = createObject(&quot;component&quot;, &quot;timesheet&quot;);
      updateTimesheet.updateTask(timesheetTask);
&lt;/cfscript&gt;
&lt;/code&gt;

Notice that this code also calls the CFC object at the end. The data itself isn&apos;t massively important, it&apos;s a time object for recording tasks.

Next we have the function, which accepts a Struct() argument called &apos;taskStruct&apos;. I then loop through the structure, and populate a SQL query using the keys from a collection. The only logic is a check to see if it is the last structure element, as this controls the &apos;,&apos; placement.

 &lt;code&gt;
      &lt;cffunction name=&quot;updateTask&quot; access=&quot;remote&quot; returntype=&quot;string&quot; hint=&quot;Creates a record for timesheet tasks&quot;&gt;
            &lt;cfargument name=&quot;taskStruct&quot; type=&quot;struct&quot; required=&quot;yes&quot;&gt;
      &lt;cfset var count = 0&gt;

            &lt;cfdump var=&quot;#arguments.taskStruct#&quot;&gt;
      &lt;cfset variables.structSize = structCount(arguments.taskStruct)&gt;
 
      &lt;cfquery datasource=&quot;#application.dsn#&quot;&gt;
            INSERT INTO [dbo].[timesheet]
           (&lt;cfloop collection=&quot;#arguments.taskStruct#&quot; item=&quot;key&quot;&gt;
                        [#key#]
                        &lt;cfset count = count + 1&gt;
                        &lt;cfif count LT variables.structSize&gt;,&lt;/cfif&gt;
                  &lt;/cfloop&gt;)
    
      &lt;cfset count = 0&gt; 
      
      VALUES(&lt;cfloop collection=&quot;#arguments.taskStruct#&quot; item=&quot;key&quot;&gt;
                  &apos;#arguments.taskStruct[key]#&apos;
               &lt;cfset count = count + 1&gt;
               &lt;cfif count LT variables.structSize&gt;,&lt;/cfif&gt;
               &lt;/cfloop&gt;)
            &lt;/cfquery&gt;
 
            &lt;cfreturn true&gt;
      &lt;/cffunction&gt;
&lt;/code&gt;

That will insert your Struct into a database, in small and tidy manner. It was somewhere around here that we started using cfproperty tags, and creating strongly typed objects for Flex.
				
				</description>
				
				
				<category>Software Architecture</category>
				
				<category>Flex Remoting</category>
				
				<category>Coldfusion</category>
				
				<category>SQL</category>
				
				<pubDate>Wed, 26 Aug 2009 16:42:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/8/26/Example-of-inserting-a-Struct-into-a-database-using-keys</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>AIR Phone Book application - Part 1 (CFC and GUI)</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/4/3/AIR-Phone-Book-application--Part-1-CFC-and-GUI</link>
				<description>
				
				I&apos;m always asking what peoples phone numbers are in the office, we currently don&apos;t have any internal communications (like an intranet) so I thought I&apos;d create a handy phone book application in AIR.

With FLEX of AIR applications I often wireframe them up with the data model in mind first. If you know what data you are going to display, and the format and delivery mechanism of that data, it can often have a large impact on the design and layout of your application.

In this instance I was just returning a simple query object of users and their phone numbers and a thumbnail image.

&lt;h3&gt;The CFC&lt;/h3&gt;

My preferred server language is ColdFusion, so my service is a CFC object.

&lt;code&gt;
&lt;cfcomponent hint=&quot;WLD phoneBook&quot; output=&quot;false&quot;&gt;

	&lt;cffunction name=&quot;getData&quot; access=&quot;remote&quot; hint=&quot;Gets phoneBook data&quot; returntype=&quot;query&quot;&gt;
	
		&lt;cfquery datasource=&quot;#application.dns#&quot; name=&quot;qGetPB&quot;&gt;
			select 	id AS ID, 
					name AS Name,
					number AS No,
					image As Image
			from phonebook 
			Order by name
		&lt;/cfquery&gt;

		&lt;cfreturn qGetPB&gt;
	&lt;/cffunction&gt;
	
&lt;/cfcomponent&gt;
&lt;/code&gt;

In my example I&apos;m using an MS SQL database, so I have included the creation script here:

&lt;code&gt;
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[phonebook](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[name] [varchar](20) NULL DEFAULT (NULL),
	[number] [int] NULL DEFAULT (NULL),
	[image] [varchar](55) NULL DEFAULT (NULL)
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
&lt;/code&gt;

Now that we know what the data will look like we can build the GUI front end.

My display layer is going to be a canvas, with another canvas inside it, to create a bordered effect.

Then I have a DataGrid, with a click event that will call an AS function. This will control the displaying of an image that corresponds to the user being clicked. Its always nice to see who you want to call!

&lt;code&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;/code&gt;

My &apos;userImage&apos;has a showEffect attribute, that uses an image fadeIn method. It fades in the first image called, but not any others, I&apos;ve had a play around with this, and I can&apos;t get it to fade in subsequent images, so if anyone has any ideas let me know!

Lastly I have added some chrome controls, as I will be removing the standard chrome, and building my own.

Now, on to the &lt;a href=&quot;http://www.mccran.co.uk/index.cfm/2009/4/3/AIR-Phone-Book-application--Part-2-Functions-and-WebService&quot;&gt;functions&lt;/a&gt;.
				
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>Coldfusion</category>
				
				<category>AIR</category>
				
				<category>SQL</category>
				
				<category>RIA</category>
				
				<pubDate>Fri, 03 Apr 2009 14:46:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/4/3/AIR-Phone-Book-application--Part-1-CFC-and-GUI</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>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>Init method for coldfusion cfc&apos;s</title>
				<link>http://www.mccran.co.uk/index.cfm/2008/7/7/Init-method-for-coldfusion-cfcs</link>
				<description>
				
				I&apos;m lucky enough to be working in an environment that is small enough to allow me access to our whole suite of coldfusion cfc&apos;s. So i generally know pretty much what they all do, but what if your interrogating unknown cfc&apos;s?

Well you can use the init() method.
				 [More]
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>Coldfusion</category>
				
				<pubDate>Mon, 07 Jul 2008 16:21:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2008/7/7/Init-method-for-coldfusion-cfcs</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Matching date ranges to flex arrays in SQL queries</title>
				<link>http://www.mccran.co.uk/index.cfm/2008/7/3/Matching-date-ranges-to-flex-arrays-in-SQL-queries</link>
				<description>
				
				Whilst writing a search function for a flex applicaiton I needed to be able to filter results back to flex from a remote cfc by a variety of criteria. Two of these were the month, and the year. So here&apos;s a handy way of doing it.
				 [More]
				</description>
				
				
				<category>Flex Remoting</category>
				
				<category>SQL</category>
				
				<pubDate>Thu, 03 Jul 2008 17:05:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2008/7/3/Matching-date-ranges-to-flex-arrays-in-SQL-queries</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>
			
		 	
			</channel></rss>