AIR 2.0 and Flash 10.1 Betas

As I (slowly) try to recover from yesterday, I thought I'd send out a quick reminder to folks that the latest betas of both AIR 2.0 and Flash 10.1 are available.

AIR 2.0 should be an amazing release. I highly recommend catching up on Christian Cantrell's blog as he has quite a few entries on the new release.

Flash 10.1 is also now at beta 2. I've not followed the news much on this but from what I can see this will be an important update for mobile devices.

I hate to sound like a broken record, but, I'll say it again. For my readers who only know ColdFusion, now is the time to expand your skills and pick up AIR. Even if you don't want to learn Flex (which I recommend as well), you can simply build upon your existing HTML and JavaScript knowledge by adding the power of AIR.


ColdFusion as a Service Examples - Images

I promised a few weeks ago that I'd eventually get around to posting some of the code from my RIAUnleashed presentation. This morning I'm going to share two of them - both related to the Image service. The first one is really simple. It allows you to enter a URL to an image. CFaaS is then used to perform a gray scale on the image and return the result to the user. The code behind this demo could be a bit cleaner perhaps, but let's take a look at it.

[More]

AIR 2.0 Released to Labs

Woot! Adobe's AIR 2.0 has now been released to Labs. (Along with the Flash Player 10.1 pre-release.) I'd recommend this excellent blog article by Christian Cantrell for more information: AIR 2 Public Beta Resources.

I'd love to know - who out there is using AIR? Either for their business or for fun.

Exploring CFaaS Presentation

Hey folks - here are the slides and code from my Exploring ColdFusion as a Service presentation at RIAUnleashed. Please note that these slides and code deserve some explanation. I plan on doing a series of blog posts on CFaaS over the next few days to help others learn about this new ColdFusion 9 feature. This code comes with a license requirement that you don't laugh at my Flex code.

Building an AIR Spy Application

Earlier today I twittered that I wanted to build a simple AIR application. The idea would be to use the web cam on my Macbook Pro and snap a picture every minute or so. I thought this would be relatively easily in AIR and I wasn't surprised at all. Let me be honest - I did not do heavy research into this. I found two really good web sites and built my application from what I saw there. There is - most definitely - probably much cleaner ways of doing this. I built this for fun - nothing more. That being said, let's take a look.

[More]

jQuery/AIR Quickie - YQL Tester

This is absolutely pointless, but I love the fact that it took all of five minutes to write. I've been playing quite a bit with YQL lately (I wrote about it here) and even wrote a simple ColdFusion wrapper for it. I thought I'd take a look at how difficult it would be to write a jQuery based "tester". Ie, something I could write basic YQL text in and then see the results. I began with a few building HTML building blocks:

[More]

Odd jQuery/Keypress/AIR Issue

I'm looking for some help here folks. I'm working on a new blog series for InsideRIA (don't forget folks, most of my RIA stuff is there) involving jQuery and AIR. I've done a few entries already on using Aptana to build an application and now I want to dig a bit deeper into jQuery/AIR integration. I've built a simple application that's going to be the starting point for the new series. Right now it is barely AIR. By that I mean it doesn't use any of the APIs at all. Outside of running as an application, it's just a HTML window. That being said, while working on the application I noticed something truly odd I wanted to share with folks.

[More]

CFaaS Demo - Dead Bike

One of the cool new features of ColdFusion 9 is CFaaS, or ColdFusion as a Service. I'll be honest, I hate the abbreviation. It makes me think of a disease. But - I'll get over it since the feature itself is so impressive. During the ColdFusion Meetup (recording here), ColdFusion Evangelist Terry Ryan demonstrated using CFDOCUMENT remotely via Flex. In his demo, he enters some text, clicks a button, and gets the URL to download a PDF. This reminded me that many moons ago, earlier in the ColdFusion 9 beta, I had created a simple demo called DeadBike. (I'll buy you a beer at CFUNITED if you can guess why.) Here is a quick video showing it in action (clicking will take you to a full screen view, so I'd recommend 'open in new tab'): So the code behind this is very similar to what Terry showed. Note that I've been lazy and hard coded all the security information within Flex.
   view plainprintabout
 <?xml version="1.0" encoding="utf-8"?>
 <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:cf="coldfusion.service.mxml.*" layout="absolute" viewSourceURL="srcview/index.html">
 
 <cf:Config id="conf" cfServer="127.0.0.1" cfPort="8502" serviceUserName="service" servicePassword="service" />
 
 <cf:Document id="doctestnow" action="generate" format="pdf" result="handleResult(event)" fault="handleError(event)" />
 
 <mx:Script>
 <![CDATA[
10  import mx.rpc.events.ResultEvent;
11  
12  public var res:String = new String();
13  
14  private function renderSourceAsPDF():void {
15      var source:String = sourceText.text;
16      if(source.length == 0) return
17      doctestnow.content = source;
18      doctestnow.execute();
19  }        
20  
21  private function handleResult(event:ResultEvent):void {
22      res=event.result.toString();
23      pdfviewer.location=res;    
24  }
25  
26  private function handleError(event:Event):void {
27   mx.controls.Alert.show(event.toString());
28  }
29  
30  ]]>
31  </mx:Script>
32  
33  <mx:HDividedBox width="100%" height="100%">
34  
35      <!-- source side -->    
36      <mx:VBox width="50%" height="100%">
37          
38          <mx:Panel title="Source" width="100%" height="100%">    
39              <mx:TextArea id="sourceText" width="100%" height="100%" />
40          </mx:Panel>
41      
42          <mx:HBox horizontalAlign="right" width="100%">
43              <mx:Button label="Render PDF" click="renderSourceAsPDF()" />
44          </mx:HBox>
45  
46      </mx:VBox>
47      
48      <!-- render side -->
49      <mx:Panel title="PDF" width="50%" height="100%">    
50          
51           <mx:HTML id="pdfviewer" width="100%" height="100%" />
52  
53      </mx:Panel>
54  
55  </mx:HDividedBox>
56  
57  </mx:WindowedApplication>
Let's focus on the interesting bits first. You can find the connection/service information here:
   view plainprintabout
 <cf:Config id="conf" cfServer="127.0.0.1" cfPort="8502" serviceUserName="service" servicePassword="service" />
 
 <cf:Document id="doctestnow" action="generate" format="pdf" result="handleResult(event)" fault="handleError(event)" />
CFaaS has two special security requirements. First, you must go to User Management and specifically create a user and then give them access to particular services. In this case I gave the user, service, access to the Document service. Secondly, you have to specify which IP addresses are allowed to use the service. Now - I have to say - this is a bit troubling. I get the idea behind it - but it's going to be a problem for an intranet. I can't imagine you would need to enter each and every single IP address of your corporation by hand. But - that seems to be the case for right now. Hopefully that will change before release. The code handling rendering is about as simple as it gets:
   view plainprintabout
 private function renderSourceAsPDF():void {
     var source:String = sourceText.text;
     if(source.length == 0) return
     doctestnow.content = source;
     doctestnow.execute();
 }
Essentially - if I ttyped something, execute the CF service. My services result handler then simply uses the HTML component to render the PDF.
   view plainprintabout
 private function handleResult(event:ResultEvent):void {
     res=event.result.toString();
     pdfviewer.location=res;    
 }
Note that I had gotten a URL back, like Terry's demo, but I went ahead and loaded the result in the component. I was going to package up the demo, but it's usability by the public is very limited. I'd recommend simply copying my code into a new Flex Builder project. Remember to include the cfservices.swc file with your project!

Finding the username in an AIR app, and a quick binding tip

Gary asked me an interesting question relating to AIR applications. He wanted to know if there was a way for an AIR application to know the username of the current user. I would have guessed that this would be part of the AIR API, but after a bit of searching and asking around, it turns out that this is not the case. While there isn't a direct API, there is a nice workaround that I found on Stack Overflow (Get the current logged in OS user in Adobe Air). The solution simply assumes that all users have a base directory that includes their username. On my Mac, it is "/Users/ray". On my Windows box (yes, I'm ashamed, I still keep one around), the directory is "c:\documents and settings\administrator". So this technique seems like a good one. You could certainly use it to suggest the current username. Here is a simple demo that Gary cooked up using this technique:
   view plainprintabout
 <?xml version="1.0" encoding="utf-8"?>
 <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" horizontalAlign="center" verticalAlign="middle">
 
 <mx:Script>
 <![CDATA[
 
 public function currentOSUser():String {
     var userDir:String = File.userDirectory.nativePath;
     var userName:String = userDir.substr(userDir.lastIndexOf(File.separator) + 1);
10      return userName;
11  }    
12      
13  ]]>
14  </mx:Script>
15  
16  <mx:Text text="{currentOSUser()}" fontSize="75" horizontalCenter="true"/>
17  <mx:Text text="is a winner!" fontSize="20" />
18  
19  </mx:WindowedApplication>
I modified it a bit just to simplify things. Running it on my Mac I see: On my PC (oh, and I loved how the AIR installer noticed my PC was a bit behind on the AIR SDK and updated itself) it displayed: Ok, one last tip. Gary was trying to use binding with this method and had trouble getting it working. Let's look at what he did.
   view plainprintabout
 public function currentOSUser():String {
 var userDir:String = File.userDirectory.nativePath;
 var userName:String = userDir.substr(userDir.lastIndexOf(File.separator) + 1);
 return userName;
 }
 
 protected function list_creationCompleteHandler(event:FlexEvent):void {
 getMyUnitResult.token = Widget.getMyUnit("{currentOSUser()}");
 }
This didn't work for him. Notice the binding inside the function? That's simply not a place where you can use binding. In this case the solution was simpler code:
   view plainprintabout
 getMyUnitResult.token = Widget.gyMyUnit(currentOSUser())
My understanding is that you can only use bindings in the attributes of components. However, don't take my word for it. I found a nice article at Adobe specifically on binding: Using data binding Hope this helps!

Follow up - Flash Builder 4, ColdFusion CFCs, and AIR

I've done a few blog entries recently showing simple examples of connecting to a ColdFusion CFC via Flex. My last blog entry demonstrated this using Flash Builder 4. A reader there asked me to create an example of this in AIR. It just took a few minutes, so let me walk you through the process (and please forgive me but let me give the normal disclaimer, I'm new to Flex, blah blah blah).

[More]

More Entries