I promised to blog about my adventures exploring what ColdFusion has to offer, and ColdFusion Components (CFC's) was one of the first things I tried.
I've got to admit its still a little uncomfortable writing non-interface related markup in tags, though of course you can do the same with Flex, and technically this can also be done using CFScript over CFML.
This particular HelloWorld component has just one function "sayHello" and you can probably figure out what it does. It requires one argument "name" of type string and returns a string using the given name.
To integrate this in a Flex application, things are very straightforward. The easiest option you have is using the Flash Remoting gateway that comes with ColdFusion.
In the example above the only thing we actually need to connect to the HelloWorld CFC is the RemoteObject tag. We first set the destination property to "ColdFusion" and point the endpoint to the ColdFusion remoting gateway location. The source property is the name of our CFC (HelloWorld.cfc) without the .cfc extension.
Now that is set up we can call methods in the CFC by referencing the id of the RemoteObject instance, e.g. cfc_service.sayHello() as you see happens when the button component gets clicked. The RemoteObject tag is also set up to listen to the result event and then populates the result in the result textinput component we set up.
In a more real world example, I'd recommend creating an actual ActionScript 3.0 result handler function rather than writing that as inline code.
You can see this is pretty trivial to set up. In an upcoming blog post I'll show you how to access this same CFC as a SOAP webservice from PHP or other scripting languages.