0

ColdFusion 8 and its Cool Ability to Compile Flex Applications

ColdFusion 8

Tom 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:

Flex Made by cfm file in ColdFusion8

 

.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:

Flex Compiled by ColdFusion8

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:

Error Message

 

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.

tags:
ColdFusion 8
Steven Erat said:
 
For as long as the generated mxml code does not change, the resultant swf will be kept in cache and served from cache for subsequent requests. If the dynamically generated mxml changes for any reason, then it will be recompiled and then cached again. If the generated mxml does not change, the only performance hit on the server would be the first compile.
 
posted 854 days ago
Add Comment Reply to: this comment OR this thread
 
 
Cool. Thanks for posting that.
 
posted 853 days ago
Add Comment Reply to: this comment OR this thread
 
Patrick Whittingham said:
 
Sam -

Thanks Sam. This is cool that I can create some flex code inside a cfm file. I guess I can know put that code inside a tag and write it out as a mxml file.
 
posted 851 days ago
Add Comment Reply to: this comment OR this thread
 
Simon Wallace-Jones said:
 
Thanks Sam. Exciting feature however where does cf-bootstrap-for-flex.jar get installed from? I am running the current CF8 beta 8,0,0,171647 and do not get this jar file.
 
posted 850 days ago
Add Comment Reply to: this comment OR this thread
 
 
@Simon: Did you install LiveCycle Data Services Express when installing CF? Thats where the magic jar files lives.
 
posted 849 days ago
Add Comment Reply to: this comment OR this thread
 
Mickael Shahinian said:
 
Thanks Sam. This works too:
cfimport prefix="cfmxml" taglib="/WEB-INF/lib/cf-bootstrap-for-flex.jar">

select * from artisans


http://www.adobe.com/2006/mxml" layout="vertical" width="470" height="380" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FCFBF7, #FFE869]">

























Although when i am trying this:



It is showing only last record :(
 
posted 846 days ago
Add Comment Reply to: this comment OR this thread
 
shahinyan said:
 
Also i've mentioned that after changing code it creates new swf file without deleting previous one. Dont know if this happens only for me.
 
posted 846 days ago
Add Comment Reply to: this comment OR this thread
 

Search

Twitter
You should follow me on Twitter here
About Me
I am a 34-year old Web Developer specializing in ColdFusion. I live and work in downtown Washington, DC with my wife and two daughters. Read more About Me

2007 CFeMmy Best Newcommer winner
As voted on by fellow CF Bloggers.
CFinNC - Carolina ColdFusion / Flex / Air Conference - Oct 17-18, 2009