ColdFusion 8 and its Cool Ability to Compile Flex Applications
ColdFusion 8Tom Jordahl at the very end of his presentation at CFUnited mentioned two cool ways ColdFusion 8 has of compiling Flex.
Compile Flex In a ColdFusion File
By importing the, extremely descriptive, cf-bootstrap-for-flex.jar it is possible to combine ColdFusion and Flex. Take a look at the following example which outputs some ColdFusion variables (it could also use any ColdFusion tags):
<cfimport prefix="cfmxml" taglib="/WEB-INF/lib/cf-bootstrap-for-flex.jar">
<cfmxml:mxml>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="470" height="380" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FCFBF7, #FFE869]">
<mx:Label text="Flex Made by cfm file in ColdFusion8" fontFamily="Georgia" fontWeight="bold" fontSize="18"/>
<cfoutput>
<mx:Text text="#server.ColdFusion.ProductName# Version #left(server.ColdFusion.ProductVersion,1)#"/>
<mx:Text text="URL name: #url.name#"/>
</cfoutput>
<mx:TabNavigator width="200" height="217">
<mx:Canvas label="Tab 1" width="100%" height="100%" />
<mx:Canvas label="Tab 2" width="100%" height="100%" />
<mx:Canvas label="Tab 3" width="100%" height="100%" />
</mx:TabNavigator>
</mx:Application>
</cfmxml:mxml>When run produces:

.mxml Files Compiled by ColdFusion
ColdFusion 8 is set up to compile mxml files directly. I really like this feature as my whole development life I have made changes in an editor, flipped to a browser and hit reload. Along comes Flex and changes that with the need to click to some little Run button. Now ColdFusion8 takes me back to my roots. You can not include ColdFusion variables or logic though.
Anyhow, here's the code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="470" height="380" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FCFBF7, #FFE869]">
<mx:Label text="Flex Compiled by ColdFusion" fontFamily="Georgia" fontWeight="bold" fontSize="18"/>
<mx:TabNavigator width="200" height="217">
<mx:Canvas label="Tab 1" width="100%" height="100%" />
<mx:Canvas label="Tab 2" width="100%" height="100%" />
<mx:Canvas label="Tab 3" width="100%" height="100%" />
</mx:TabNavigator>
</mx:Application>And the screen shot:

Pretty cool, huh?
What happens if there is an error in your code? Well, if it is a ColdFusion error then you get the normal ColdFusion error. If its a Flex error, and I've been getting plenty of these being a newbie, you get this:

I would not advise using this in production unless you have an extremely powerful server and very few users. But in development it can be quite useful. Say you have a base mxml file but want to customize it for different clients, use the first method and alter options based on a url variable.





Loading....