tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/39-use-mediator-in-a-comandRobotlegs: Discussion 2013-04-28T10:30:28Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/8716132010-01-18T16:43:23Z2010-01-18T16:43:23Zuse mediator in a comand<div><p>Hi Seb,</p>
<p>you really, really don't want to do that. I mean: really!</p>
<p>If you absolutely must have the command know about the mediator,
add<br>
it as a payload to the event the command is mapped to:</p>
<p>package {<br></p>
<pre>
<code>public class MyMediatorEvent
{
public var mediator : MyMediator;
public function MyMediatorEvent(type : String, mediator : MyMediator)
{
this.mediator = mediator;
}
}</code>
</pre>
<p>}</p>
<p>The downside is that you have to change the calling side (i.e.,
the<br>
class that dispatches the event, plus the event itself). On the
other<br>
hand, you'd also have to do that to enable injecting the
mediator.</p>
<p>For the sake of completeness, here's how you'd inject the
mediator:</p>
<p>In your mediator:<br>
injector.mapValue(MyMediator, this);<br>
dispatch([the event the command is mapped to]);<br>
injector.unmap(MyMediator);</p>
<p>in your command:<br>
[inject] public var mediator : MyMediator;</p>
<p>hope that helps,<br>
till</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/8716132010-01-18T21:29:37Z2010-01-18T21:29:37Zuse mediator in a comand<div><p>Hi,</p>
<p>in my app context I have the following line</p>
<p>mediatorMap.mapView(ImageView, ImageViewMediator);</p>
<p>which binds the ImageView to the ImageViewMediator</p>
<p>when the command which is contain this following code is ran</p>
<p>[Inject]</p>
<p>private var imageViewMediator:ImageViewMediator;</p>
<p>public function SetSelectedImageCommand()</p>
<p>{</p>
<p>super();</p>
<p>}</p>
<p>override public function execute():void</p>
<p>{</p>
<p>trace(imageViewMediator)</p>
<p>}</p>
<p>the trace is null. Any idea why? This why I posted the thread. I
thought i<br>
was doing something wrong but it looks like from your example I'm
not. Or am<br>
I?</p>
<p>thanks</p>
<p>2010/1/18 tschneidereit <<br>
<a href=
"mailto:tender+d177270d20ec98e80743d8a184b7f1964a2e4fd80@tenderapp.com">
tender+d177270d20ec98e80743d8a184b7f1964a2e4fd80@tenderapp.com</a><<a href="mailto:tender%2Bd177270d20ec98e80743d8a184b7f1964a2e4fd80@tenderapp.com">tender%2Bd177270d20ec98e80743d8a184b7f1964a2e4fd80@tenderapp.com</a>><br></p></div>Sebastien Jouhanstag:robotlegs.tenderapp.com,2009-10-18:Comment/8716132010-01-21T18:35:16Z2010-01-21T18:35:16Zuse mediator in a comand<div><p>Automatic injections only work for public members, so you'd have
to<br>
make imageViewMediator public.</p></div>Till Schneidereit