tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/6190-how-do-i-access-the-stage-from-a-mediatorRobotlegs: Discussion 2017-04-13T14:34:40Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/420638622017-03-06T15:48:16Z2017-03-06T15:48:16ZHow do I access the stage from a Mediator?<div><p>Hey Darryl,</p>
<p>For some reasons, your message has landed in the 'spam' folder
of this forum. I restored it today.</p>
<p>This would be one solution:</p>
<pre>
<code>[Inject]
public var view:YourView;
override public function initialize():void
{
view.stage.addEventListener(MouseEvent.CLICK, onTargetClick);
}
//in case the view is going to be removed from stage::
override public function destroy():void
{
view.stage.removeEventListener(MouseEvent.CLICK, onTargetClick);
super.destroy();
}</code>
</pre>
<p>If the view is going to be removed from stage at some point,
you'd need to explicitly remove the listener inside of the
destroy() method, as shown above. The reason for that is that a
mediator which keeps a reference to its view can't be
destroyed.</p>
<p>Another solution would be to let the view listen for the
MouseEvent and in the handler of the event dispatch a custom event
to which the mediator would listen:</p>
<pre>
<code>override public function initialize():void
{
addViewListener(SomeViewEvent.GLOBAL_CLICK, onTargetClick);
}</code>
</pre>
<p>In this case, you don't need to remove the event listener inside
of destroy(), the mediator will take care of it automatically.</p>
<p>I'd prefer the second solution.</p>
<p>I hope this helps.<br>
Ondina</p></div>Ondina D.F.