This content has been marked as final. Show 3 replies
If you are going to use the same AS classes in multiple projects you definitely want to use a Flex library. Your ActionScript classes will wind up in a SWC which you can use in the libraryPath of any other Flex project.
I would create and maintain the CFCs separately from the Flex projects. The reason being is that you ought to treat them as if you bought them from a third party and want to maintain them on a separate development cycle. For example, suppose Project A is moving to version 1.5 and needs a modification to one of the CFCs. You don't want to have to deal with Project B which is still using version 1.0. If you were to buy these CFCs from someplace, how would you want them to be packaged? Use that as a guideline.
Your common AS classes which are the CFC counterparts probably don't mean much without the CFCs. So I would include in that Flex library a class to interface (RemoteObject) with the CFCs so that the SWC is self-contained. Again, if you need to add or change an AS file in response to a change in the CFCs, you have better version control keeping these together. Again, treat these like a third-party product.
So your Flex library (AS classes + RemoteObject calls) now becomes your API for all your applications.
One final note: your projects sounds ideal for Flex 2.0.1 Modules. I wrote a quick intro to them on my blog and you can read more about them in the Flex livedocs under Creating Modular Applications..
I did look at your blog before I posted but was not sure if Modules were right for me. I will examine them closer.
Although I can do some quite advaced things in flex (thanks to your blog and others,) I have no Idea how I would create a class to interface (RemoteObject) I only have used Remote Object as a mxml tag and not as actionscript(if that makes sense to you).
EDIT: I found it in the Flex help under "Calling services in ActionScript"
You can put the RemoteObject mxml tag into a Canvas of width=0 height=0 and place it on the Application. That was a common way in Flex 1.5 when data services could not (easily) be written in ActionScript.
In Flex 2.0, you can do either. Here's the gist of doing in with AS (assume the class is DataServices.as):
private var appCFC:RemoteObject;
private function initServices() : void
appCFC = new RemoteObject("ColdFusion");
appCFC.source = "your.cfc.here";
appCFC is the RemoteObject and is created in the initServices function of the DataServices class. The source property is the CFC that the RemoteObject will talk to. Then you add event listeners for the result of every CFFunction in the CFC that will be called. For example, the CFC might have a CFFunction called getSomeData which, when called from Flex, will trigger the get_some_data_result function when it returns the data.
That should get you started.