3 Replies Latest reply on Jan 19, 2007 6:36 PM by peterent

    Sharing CFC’s with many Flex Projects

    mltv Level 1
      I am building a large application that runs our company to replace the old CF/Flash app I built myself over the last 6 years.
      I am using Flex and Cold Fusion CFC’s to build the app from scratch.
      This app will be made up of many 100’s of smaller apps that handle:
      User administration, Inventory, Quotes, Contracts, Invoices, Missing and Damage reports, Truck runs etc.

      First I built our Purchase Order system and then I built the Inventory system.
      I built them as separate Flex Projects and saw that they used many of the same CFC’s(that I created in each project) and that down the line I would have to change many projects CFC’s and Actionscript value objects (models) if I made any changes to the database tables that they called.

      I want to create one set of CFC’s and Actionscript value objects that any project I do on this site can use.

      I am creating these CFC’s and .as files with “Create CFC” Cold Fusion Wizard.

      I saw that I would have to change the way I was working in separate projects.

      I thought about making one Flex project with many applications in it but it seems like this will not scale well over time and could become a mess.

      I seem to be able to make a Flex Library project that would hold my .as models files and I could add that library to each project but I don’t think I can call CFC’s that way.

      I could make and publish a Flex Project that does nothing but hold the CFC’s and point my remote object call to that project but I would not be able to call the .as files unless I referenced that project and this solution started to feel like one of my classic Kludges that would prove a bad choice over time

      Any advice on the overall architecture errors I am making and how I should build to make these assets available to all my projects/subapplications?
        • 1. Re: Sharing CFC’s with many Flex Projects
          peterent Level 2
          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..

          Good luck!
          • 2. Sharing CFC’s with many Flex Projects
            mltv Level 1
            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"
            Thanks again.
            • 3. Re: Sharing CFC’s with many Flex Projects
              peterent Level 2
              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):

              import mx.rpc.events.ResultEvent;
              import mx.rpc.events.FaultEvent;
              import mx.rpc.remoting.RemoteObject;

              private var appCFC:RemoteObject;

              private function initServices() : void
              {
              appCFC = new RemoteObject("ColdFusion");
              appCFC.source = "your.cfc.here";
              appCFC.addEventListener(FaultEvent.FAULT, handleFault);
              appCFC.loginUser.addEventListener(ResultEvent.RESULT,user_login_result);
              appCFC.getSomeData.addEventListener(ResultEvent.RESULT,get_some_data_result);
              appCFC.saveSomeData.addEventListener(ResultEvent.RESULT,save_some_data_result);

              }

              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.