Posted in jQuery, Flex, ColdFusion | Posted on 11-04-2010 | 3,317 views
This is probably one more blog entry of mine that falls into the "obvious" category, but until I tried it today I didn't know it was possible so hopefully I'm not the only one. I don't normally use the debugger in ColdFusion Builder. There isn't anything wrong with it - it just doesn't really mesh with the way I like to write code. On the flip side, I make a heck of a lot of use out of the debugger in Flash Builder. Why do I use it more there and less in ColdFusion? No idea. That being said, a reader this week asked me an interesting question. He is using Flash Builder and wanted to know about debugging on the server side. I knew you could debug the Flex side of course. You can also easily debug the network communications. What I wasn't sure of was how I'd handle debugging on the ColdFusion Builder side when I'm actually using Flash Builder. The debuggers in both products aren't related. (Well, I assume they share some code at the Eclipse level.) Here is what I found out.
I began by creating a super simple CFC to act as my service. I put some bogus code in there just to give me a few lines of logic.
2
3 remote function double(numeric x) {
4 var thisisdumb = now();
5 var thisismoredumb = randRange(1,1000);
6 var result = arguments.x*2;
7 return result;
8 }
9
10}
Over in Flash Builder I then created an extremely simple front end.
2<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
3 xmlns:s="library://ns.adobe.com/flex/spark"
4 xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
5
6 <fx:Declarations>
7 <mx:RemoteObject destination="ColdFusion" source="double" id="doubleService">
8 <mx:method name="double" result="handleResult(event)" fault="handleFault(event)" />
9 </mx:RemoteObject>
10 </fx:Declarations>
11
12 <fx:Script>
13 <![CDATA[
14 import mx.controls.Alert;
15 import mx.rpc.events.FaultEvent;
16 import mx.rpc.events.ResultEvent;
17
18 public function handleFault(evt:FaultEvent):void {
19 mx.controls.Alert.show(evt.toString())
20 }
21
22 public function handleResult(evt:ResultEvent):void {
23 resultValue.text = evt.result.toString()
24 }
25
26 public function tryIt():void {
27 doubleService.double(initialValue.text);
28 }
29 ]]>
30 </fx:Script>
31
32 <s:HGroup>
33
34 <s:TextInput id="initialValue" />
35 <s:Button id="doubleBtn" label="Click to double" click="tryIt()" />
36 <s:TextInput id="resultValue" />
37
38 </s:HGroup>
39
40</s:Application>
All this code does is take input from the first field and send it to my CFC. When the result is returned I place it in the second field. I hit run in Flash Builder and confirmed everything worked. I then went to ColdFusion Builder (I don't run my installs in the same Eclipse package) and switched to the ColdFusion Debugging perspective. I put a breakpoint on one of the lines and then I clicked the little green bug to start up the debugging session. This launched double.cfc in the browser which gave me the normal CFC view.

Now at this point I then switched back to my browser tab containing my Flex app. I entered another number, hit the button, and voila - all of a sudden CFBuilder is blinking in my task bar. I could see nothing being displayed in the Flex app and when I alt-tabed over to CFBuilder I was in the middle of a debugging session.

When I let the method carry on, my data was returned to Flex. I tried the same thing in a simple Ajax based application and it also worked.
Even better - I then switched over to Aptana and converted my jQuery example into a simple AIR application. I ran it and once again - the result was 'hung' up while I debugged in ColdFusion Builder.
Cool! So - as I said, I guess this is 100% expected, but it never occurred to me to try using CFBuilder's debugger like this. I can actually see myself using it more now.

