You should create your custom component so that it dispatches its own custom 
event. Then whenever that event is dispatch, you can then dispatch the 
appropriate Cairngorm even to perform whatever business logic you wish. That 
will allow you to also intercept which component instance is doing the 
broadcasting.

Dimitrios Gianninas
Optimal Payments Inc.



-----Original Message-----
From: [email protected] on behalf of Shannon
Sent: Thu 3/15/2007 6:42 PM
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

...

}



-- 
WARNING
-------
This electronic message and its attachments may contain confidential, 
proprietary or legally privileged information, which is solely for the use of 
the intended recipient.  No privilege or other rights are waived by any 
unintended transmission or unauthorized retransmission of this message.  If you 
are not the intended recipient of this message, or if you have received it in 
error, you should immediately stop reading this message and delete it and all 
attachments from your system.  The reading, distribution, copying or other use 
of this message or its attachments by unintended recipients is unauthorized and 
may be unlawful.  If you have received this e-mail in error, please notify the 
sender.

AVIS IMPORTANT
--------------
Ce message électronique et ses pièces jointes peuvent contenir des 
renseignements confidentiels, exclusifs ou légalement privilégiés destinés au 
seul usage du destinataire visé.  L'expéditeur original ne renonce à aucun 
privilège ou à aucun autre droit si le présent message a été transmis 
involontairement ou s'il est retransmis sans son autorisation.  Si vous n'êtes 
pas le destinataire visé du présent message ou si vous l'avez reçu par erreur, 
veuillez cesser immédiatement de le lire et le supprimer, ainsi que toutes ses 
pièces jointes, de votre système.  La lecture, la distribution, la copie ou 
tout autre usage du présent message ou de ses pièces jointes par des personnes 
autres que le destinataire visé ne sont pas autorisés et pourraient être 
illégaux.  Si vous avez reçu ce courrier électronique par erreur, veuillez en 
aviser l'expéditeur.

<<winmail.dat>>

Reply via email to