use mediator in a comand

seb's Avatar


18 Jan, 2010 04:33 PM


I was wondering if I could inject a mediator instance in a command? I know it's usually not good practice to do so. But in the event I really needed to do it. How would I achieve that?


  1. Support Staff 1 Posted by Till Schneidere... on 18 Jan, 2010 04:43 PM

    Till Schneidereit's Avatar

    Hi Seb,

    you really, really don't want to do that. I mean: really!

    If you absolutely must have the command know about the mediator, add
    it as a payload to the event the command is mapped to:

    package {
        public class MyMediatorEvent
            public var mediator : MyMediator;
            public function MyMediatorEvent(type : String, mediator : MyMediator)
               this.mediator = mediator;

    The downside is that you have to change the calling side (i.e., the
    class that dispatches the event, plus the event itself). On the other
    hand, you'd also have to do that to enable injecting the mediator.

    For the sake of completeness, here's how you'd inject the mediator:

    In your mediator:
    injector.mapValue(MyMediator, this);
    dispatch([the event the command is mapped to]);

    in your command:
    [inject] public var mediator : MyMediator;

    hope that helps,

  2. 2 Posted by Sebastien Jouha... on 18 Jan, 2010 09:29 PM

    Sebastien Jouhans's Avatar


    in my app context I have the following line

    mediatorMap.mapView(ImageView, ImageViewMediator);

    which binds the ImageView to the ImageViewMediator

    when the command which is contain this following code is ran


    private var imageViewMediator:ImageViewMediator;

     public function SetSelectedImageCommand()




     override public function execute():void




    the trace is null. Any idea why? This why I posted the thread. I thought i
    was doing something wrong but it looks like from your example I'm not. Or am


    2010/1/18 tschneidereit <
    [email blocked]<tender%[email blocked]>

  3. Support Staff 3 Posted by Till Schneidere... on 21 Jan, 2010 06:35 PM

    Till Schneidereit's Avatar

    Automatic injections only work for public members, so you'd have to
    make imageViewMediator public.

  4. Stray closed this discussion on 13 Feb, 2011 06:39 PM.

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

Keyboard shortcuts


? 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