How to incorporate Consumer functionatliy into Cairngorm?

Posted on 2009-02-10
Last Modified: 2013-11-11

I'm converting a Flex application to Cairngorm and haven't been able to figure out what to do with the Consumer calls.  I've read through all the documentation and included CairngormEnterprise.swc into my build and added the Consumer instance to my ServiceLocator just as with any other http or RPC call.  The error I keep on getting is this:

Only one ServiceLocator instance can be instantiated

I'm guessing this is because I'm instantiating EnterpriseServiceLocator a long with ServiceLocator but I don't what else to do since the getConsumer() method is only in the EnterpriseServiceLcoator object.

Any help would be greatly appreciated.  I've included both my delegate and ServiceLocator classes.

package control.delegates




	import mx.messaging.Consumer;


	import mx.rpc.IResponder;




	public class ReceiveMessageDelegate


		private var _responder:IResponder;

		private var _service:Consumer;


		public function ReceiveMessageDelegate(r:IResponder)


			_service = EnterpriseServiceLocator.getInstance().getConsumer("receiveMessageEvent");

			_responder = r;

			_service.addEventListener(MessageEvent.MESSAGE, _responder.result);

			_service.addEventListener(MessageFaultEvent.FAULT, _responder.fault);



		// Subscribes to the feed.

		public function subscribe():void





		// Unsubscribes to the feed.

		public function unsubscribe():void






<!-------------- ServiceLocator ------------------>


<?xml version="1.0" encoding="utf-8"?>

<rds:ServiceLocator xmlns:rds="*"






			import model.ModelLocator;



			private var __model:ModelLocator=ModelLocator.getInstance();





	<mx:Consumer id="receiveMessageEvent" destination="ColdFusionGateway" />




Open in new window

Question by:blue44

    Accepted Solution

    Of course, right after I posted this, I figured it out.  I'm not sure why this is the case, but you have to have Caringrom.swc and CairngormEnterprise.swc in the lib directory of your Flex project not as separate swcs -- if that makes sense.  This way, the getConsumer() method is available from the ServiceLocator class so there's no need to instantiate EnterpriseServiceLocater either.  Nasty, nasty, one...

    Hope this helps some other hapless soul out there...

    Expert Comment

    Nice work blue44. Could you give an example of how you changed you code to accommodate this?

    Author Comment

    Well, it's been over a year so I had to go back and review the code.  All I did was manually add both the Cairngorm.swc and CairngormEnterprise.swc to the lib directory in a Flex Project (assuming you're utilizing Flex Builder).  Then, if you go to your project properties > Flex Build Path, you'll find both under the lib directory.  Hope this helps!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
    While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
    In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
    The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now