You're doing something very weird, but I can't figure out exactly what since you've mucked with Cairngorm.
The point of the Front Controller is that there's only one. If you have two components in your app, and they both are set to fire the same event when a certain action occurs, the same action is supposed to happen each time. That's the point -- events are tied to user gestures. The same event always calls the same command. If you want different things to happen when different actions occur, you have two choices: 1) put some data into the event you dispatch, and have your Command class do different things depending on that data 2) fire different events. It sounds like you have the concept of the CairngormEventDispatcher a little off as well. It's probably best to state what you're trying to do with an example instead of code. -Mark Hawley > > From: "Shannon" <[EMAIL PROTECTED]> > Date: 2007/03/15 Thu PM 04:42:01 CST > To: [email protected] > Subject: [flexcoders] Cairngorm FrontController > > I am new to Cairngorm and Flex (I'm All About Flash) so bear with me. > > I am creating a component and I want it to use Cairngorm. I also want > to be sure that some events fired from the component are only heard > by the Cairngorm of the single component instance. Component > namespaces won't help because I use multiple instances of the same > event, I could probably filter by instance, but I am trying not to > hack (you'll probably see the irony after the next sentence... > > If I use Cairngorm as is... ...and I utilize the Singleton > CairngormEventDispatcher, as soon as I put two instances of a > component on stage, the events from one instance cause the front > controller on the second instance to fire those events > > Sadly this is probably operator error. > > Though I am guessing that someone has had this problem before and > surely there is a best practice solution to this already, I thought I > would spend a little time to explore the issue further and find my > own solution. > > I decided to try to handle this by using separate instances of the > CairngormEventDispatcher (MyViewHelper.dispatcher) for each instance > of my component. Then I could inject that dispatcher into > MyFrontController when it is instantiated so that it knows which > dispatcher to call. > > Just when I think I am on to something, I had to override addCommand > so that it would add an event listener to that instance instead of > the Singleton CairngormEventDispatcher. This is great but it required > two modifications (minor, yet still modifications) to the Cairngorm > FrontController class in order to compile my creation. (see snippets > below) Basically I took two private things and made them protected. > > Of course this might effect other pieces I have yet to build, but my > level of mastery coerces me into believing I have found a solid > answer. <snicker/> If those iteration two guys were really geniuses > they would have made these protected in the first place. > > Ha, ha, ha, just kidding, (I crack myself up) > > So I can either use my own FrontController impl or I can ask the > question: Is this a bug in Cairngorm? Or am I correct in beleiving I > must be doing something wrong... > > Some code samples: > > // > // myViewHelper Snippet: > // > public function MyViewHelper(view:Object) > { > dispatcher = new CairngormEventDispatcher(); > controller = new MyFrontController(dispatcher); > ... > } > > // > // myFrontController Snippet: > // > public class MyFrontController extends FrontController > { > > private var dispatcher:CairngormEventDispatcher; > > public function MyFrontController(dispatcher:CairngormEventDispatcher) > { > super(); > this.dispatcher = dispatcher > ... > } > > public override function addCommand( commandName : String, > commandRef : Class ) : void > { > if( commands[ commandName ] != null ) > { > throw new Error( "Command already registered for " + commandName ); > } > commands[ commandName ] = commandRef; > dispatcher.addEventListener( commandName, executeCommand ); > } > } > > // > // Cairngorm FrontController Mods > // > public class FrontController > { > // ST - 03/15/2007 : private var commands : Dictionary = new > Dictionary(); > protected var commands : Dictionary = new Dictionary(); > > // ST - 03/15/2007 : private function executeCommand( event : > CairngormEvent ) : void > protected function executeCommand( event : CairngormEvent ) : void > > ... > > } > > > > -- John Mark Hawley The Nilbog Group 773.968.4980 (cell) ------------------------ Yahoo! Groups Sponsor --------------------~--> Something is new at Yahoo! Groups. Check out the enhanced email design. http://us.click.yahoo.com/kOt0.A/gOaOAA/yQLSAA/nhFolB/TM --------------------------------------------------------------------~-> -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) <*> To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

