addContextListener in mediator does not work (for me)

Kalle's Avatar

Kalle

14 Oct, 2010 09:23 AM

Hey,
i have a problem listening to framework events in an mediator.
following setup:

in my Service i dispatch the event:

    public class CompositionMockupService extends Actor implements ICompositionService {                
    public function CompositionMockupService() {}
    public function getComposition() : void {
        .... create mockup composition ....
        dispatch(new CompositionEvent(CompositionEvent.RECEIVED, composition));
    }
}

the service works and get called, the event is fired. in my mediator i try:

           override public function onRegister() : void {
                   compositionService.getComposition();
                   addContextListener(CompositionEvent.RECEIVED, handleResultsReceived);
    }
            private function handleResultsReceived(event:CompositionEvent) : void {
        trace('MMMANNNNDDOOO');
    }

but the listener never calles the handleResultsReceived method. not sure whats wrong....

thanks for help.
Kalle

ps the event has the override public function clone(), i use Flex 4, RL 1.3.0

  1. 1 Posted by Stray on 14 Oct, 2010 09:38 AM

    Stray's Avatar

    Is onRegister() definitely running in your mediator?

    You might have forgotten to map the mediator, or the mediator mapping might be happening after the view is already on stage (in which case it won't get created).

  2. Support Staff 2 Posted by Ondina D.F. on 14 Oct, 2010 10:14 AM

    Ondina D.F.'s Avatar

    Hi Kalle,

    ...or if the mappings are ok and in the right order in your context

    and you really want to call the Service in the onRegister of the Mediator

    try to add the listener first and then call the service

    addContextListener(CompositionEvent.RECEIVED, handleResultsReceived);

    compositionService.getComposition();

    it should work.

    Ondina

  3. 3 Posted by kalle on 14 Oct, 2010 10:26 AM

    kalle's Avatar

    ...or if the mapping are ok and in the right order in your context they are...

    and you really want to call the Service in the onRegister of the Mediator shouldn't i do that ? i read about that here: Best Practice

    try to add the listener first and then call the service hehe, yeah thats's it... thx a lot.

  4. 4 Posted by kalle on 14 Oct, 2010 10:41 AM

    kalle's Avatar

    sorry, messed up formatting:

    and you really want to call the Service in the onRegister of the Mediator

    shouldn't i do that ? i read about that here: Best Practice

    try to add the listener first and then call the service

    hehe, yeah thats's it... thx a lot.

  5. 5 Posted by Stray on 14 Oct, 2010 11:18 AM

    Stray's Avatar

    No no! Don't call the service from the mediator!

    Just make sure that the service is called *after* the mediator onRegister has run.

  6. Support Staff 6 Posted by Ondina D.F. on 14 Oct, 2010 11:33 AM

    Ondina D.F.'s Avatar

    Well, if you ask me, I’m more inclined to seek a middle path in general, and when it comes to programming, I think, asymptotic perfection might be something to look forward to, but without forgetting that perfection is never achievable or that perfection in our work field (developers) might mean rigidity or stagnation.

    I think, compromises and exceptions to the rules are necessary in order to keep a project real, flexible, and yeah efficient (deadline&Co).

    So, when you know the rules, you're allowed to break them.
    In my opinion something perfectible is better than something perfect. haha

    WOW, I can’t believe, I wrote that :P

    There are different opinions (examples) about the “proper” way of using mvcs in general and with robotlegs in particular. Probably you’ll have to decide for yourself which way to follow. And good luck with that:)

    You’ll find articles, examples and yes the Best Practices where models and services are injected into mediators!
    I’m using commands to call services from mediators, but that’s because it’s inside of a large application, where I need to access the Service from many mediators and that happens several times.
    In another, smaller application I’m breaking the rules..

    Ondina

  7. 7 Posted by Stray on 14 Oct, 2010 11:39 AM

    Stray's Avatar

    >
    > So, when you know the rules, you're allowed to break them.
    > In my opinion something perfectible is better than something perfect. haha

    True, but the question suggested that the person wasn't familiar with the rules - so learning the 'right' (ie reliable) way is a good idea.

  8. Support Staff 8 Posted by Ondina D.F. on 14 Oct, 2010 11:41 AM

    Ondina D.F.'s Avatar

    True, but the question suggested that the person wasn't familiar with the rules - so >learning the 'right' (ie reliable) way is a good idea.

    Absolutely :)

  9. 9 Posted by kalle on 14 Oct, 2010 11:46 AM

    kalle's Avatar

    nice :) got it !

    i gonna refator to the 'right' way until i know what i do :P

  10. Stray closed this discussion on 10 Feb, 2011 06:02 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac