FMS, Cairngorm, and Flex

I am releasing into the wild some code I had worked on but never really completed fully.  I was working on the creation of a FMS helpdesk application.  I wanted to integrate Flex, FMS, and Cairngorm together in to one harmonious application.  You can find my original post about working with FMS and Flex here

I am including a zip file that includes the entire application except for the ColdFusion login pieces that would check the user against a database and enter their visit.    The application will not run with out FMS and removing the CF piece, but its a complete application piece that would run otherwise.  There is a folder under the structure that contains the .asc files for FMS.  I am hoping someone out their finds is useful.

CairngormChat.zip

20 Comments

  1. I downloaded your example and tried compiling it with Cairngorm 2.1 but get this error:

    1061: Call to a possibly undefined method getNetService through a reference with static type com.adobe.cairngorm.business:ServiceLocator.

    Did you add this method to Cairngorm yourself or was it removed in the newest version of Cairngorm?

  2. I had to add this service to the ServiceLocator manually, it does not include the service. CHeck the code in the download. You are brave to move it to 2.1 :).

  3. I am about to try this out. I am relatively new to Cairngorm. What do you mean by adding this service to the ServiceLocator manually. Or maybe this will become apparent to me later…Oh and THANKS…Mister! I was looking for a Flex / Cairngorm App that connected to FMS so this is just what I was looking for. Do you know if using IResponder instead of Responder is going to be a big deal? I noticed that Responder is deprecated in Cairngorm 2.1 but then again I don’t even know what version I am using right now anyway. πŸ™‚

  4. Colin, thanks for your post. It won’t be a big problem moving from Cairngorm 2 to 2.1. Once you become familiar with Cairngorm, you will be able to replace the Responder with the IResponder, and the same with the ICommand/IValueObject. The structure will still work the same. What I mean by adding the getNetService is that I had to modify the com.adobe.cairngorm.ServiceLocator file to be able to to a NetConnection. I added the following code in the ServiceLoactor.as

    import flash.net.NetConnection;

    public function getNetService( serviceId : String ) : NetConnection
    {
    if ( this[ serviceId ] == undefined )
    throw new Error( “No service found for service name ” + serviceId );

    return this[ serviceId ];
    }

    You can’t use the default SWC file for Cairngorm, you have to either create a new Library Project and make the changes to the Cairngorm package to produce a new SWC or use the Cairngorm packages directly in your application and not use the SWC. Hope this helps!

  5. Ahh….its all starting to make sense. I was trying to figure out why you had copied the cairngorm directory so that makes sense now. I was also having trouble at first because I did not realise you had essentially coded it to you use either FMS or FDS….right? To be honest, I am still studyig it and have not connected yet but the architecture is making sense. Thanks again!…mister.

  6. Yeah, I actually coded it only for FMS because that was the server I was running at the time. But it should be able to move it up to FDS. You can see I included the older AMF code to talk with FMS.

  7. Hi,
    i want to use the example with a SharedObject

    I created the getter in ServiceLocater.as

    public function getSharedObject( serviceId : String ):SharedObject
    {
    if ( this[ serviceId ] == undefined )
    throw new Error( “No service found for service name ” + serviceId );

    return this[ serviceId ];
    }

    and at the NetConnectionService.as

    public function get sharedObject():SharedObject
    {
    if(!ro){
    ro = SharedObject.getRemote(“clientlist”, nc.uri, false);
    ro.connect(nc);
    }
    return ro;
    }

    but i get an error:
    2134 Cannot create SharedObject.

    I don’t know why …. please can’t you help me ?

    thank you

  8. Hi there. I am trying to figure out the best way to create the NetStream object and handle its events in a cairngorm sort of way. I was able to get my SharedObjectListener working great based on the Cairngorm Chat app I got here so I decided to see if the same methodology would work for NetStream. I want this NetStream to be part of the model however so I can use it for databinding to various video objects. So…..I created a NetStreamListener class and put this in my ModelLocator.as:

    public var streamListener : NetStreamListener;

    Then in my NetConnectionCommand.as, when I successfully connect, I instantiate this streamListener just as I do with the SharedObjectListener:

    sharedListener = new SharedObjectListener(); // remote shared object;
    model.streamListener = new NetStreamListener();

    In the StreamListener class just have something like this:

    public function NetStreamListener()
    {
    DebugWindow.debugHeader();
    DebugWindow.debug(“NetStreamListener”);
    nc = ServiceLocator.getInstance().getNetService(“netConnection”) as NetConnection;
    ns = new NetStream(nc);
    ns.addEventListener(NetStatusEvent.NET_STATUS, nsOnStatus);
    }
    private function nsOnStatus(event:NetStatusEvent)
    {
    DebugWindow.debugHeader();
    DebugWindow.debug(“NetStreamListener:nsOnSync”);
    for each (var i in event)
    {
    DebugWindow.debug(“nsOnSync> ” + event[i]);
    }
    }

    So my question is….is this the right way to go about creating a NetStream with the Cairngorm architecture? If not, can someone point me somewhere?

    Cheers,

    Colin

  9. Colin,

    I think this is good solution, you may even want to place the sharedListener in the model so you can access it the same way. I place variables in the model when I need to access them from the views or update them from other commands. My example was certainly not the definitive way to use Cairngorm or FMS. I have learned that Cairngorm is just a suggestion, a starting architecture that you need to modify and change to best fit your programming needs. Many of the solutions that you might come up with will have a “feel right” or “feel wrong”, but experience with the architecture and Flex will lead you in the right path. There are many ways to solve the same problem. I like your method, and would probably implement NetStream in the manner.

  10. Hi Mister,
    what is the best wai to use responder from a NetConnection? flash.net.Responders does not implements IResponder ha needed in last version of cairngorm

  11. I made a mistake in my explanation; i’m using flex & cairngorm, i extended ServiceLocator as in your example but i need to make some calls to red5 so i created a delegate class, but the NetConnection.call function require a responder that isn’t rpc.IResponder but a flash.net.Responder.

    so i was askinng a trick to use it

    this is my example of delegate

    public class NetConnectionCallsDelegate
    {
    private var nc:NetConnection;
    private var responder:Responder

    public function NetConnectionCallsDelegate( responder:Responder)
    {
    nc = ServiceLocator.getInstance().getNetConnectionService(“netConnection” );
    this.responder = responder;
    }

    public function getConnectedUsers ():void{
    nc.call(“Utils.getConnectedUsers”,responder);
    }

    }

    I thought that rpc Responders could be used only with RemoteObjects… i don’t know if i’m wrong.
    thanks

  12. thnaks Mister for your emails.

    my solution should be this one

    [as]
    import com.adobe.cairngorm.business.ServiceLocator;

    import flash.net.NetConnection;
    import flash.net.Responder;

    import mx.rpc.IResponder;

    public class NetConnectionCallsDelegate
    {
    private var nc:NetConnection;
    private var responder:IResponder;

    public function NetConnectionCallsDelegate( responder:IResponder )
    {
    nc = ServiceLocator.getInstance().getNetConnectionService(“netConnection” );
    this.responder = responder;
    }

    public function getConnectedUsers ():void{
    var flashResponder:flash.net.Responder = new Responder( onConnectedUsersResult, onFault );
    nc.call(“saluta”, flashResponder);

    }

    /***********************************************************
    * EVENTS
    * ********************************************************/

    private function onFault( obj:Object ):void{
    trace(“NetConnection Call Failed: ” + obj);
    this.responder.fault( obj );
    }

    private function onConnectedUsersResult( obj:Object ):void{
    this.responder.result( obj );
    }

    }
    [/as]

    if someone has a better solution i’ll be glad to know it

    thanks
    Teo

  13. Hi Mister,

    Thanks for application, It helps me a lot n lot. Fantastic application. Now I am having a scenario like to save the information in Shared Object so that the clients get the updated information about all the users. How to disconnect the user and set the Property for the particular user when an user disconnects from the FMS Server. Can u suggest me idea…..!!

  14. You should really develop/expand more on this issue, it is something at what cairngorm is very difficult to grasp (not cairngorm itself, but thinking cairngormish).

    For example in a fms chat application, you would normally have a ChatEvent.MESSAGE_SENT, ChatEvent.MESSAGE_RECEIVED, transporting a MessageVO made of sender_id and message_body, managed by either one or two commands.

    You dispatch the message from the view when user hits enter key or send button and the flow continues, other have a users_so.send(‘receiveMessage’, messageVO) in the command or if one plans to record messages they can nc.call(‘receiveMessage’, null, messageVO);

    BUT THEN … when the message will be received, how the “underground” one can display the message … CAIRNGORM WAY.

    Put in a chatModel with chatLines ArrayCollection, to which a text area or a list bounds to ?

    underground !!! πŸ™‚

  15. Sry

    maybe this looks better in ServiceLocator?

    net:NetConnection id=”myNetConnection”

    with:

    xmlns:net=”flash.net.*” in ServiceLocator tag

Comments are closed.