tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/1162-is-addviewlistener-similar-to-viewaddeventlistnerRobotlegs: Discussion 2012-10-24T07:31:24Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/198305322012-10-19T20:03:04Z2012-10-19T20:03:04Zis addViewListener similar to view.addEventListner ? <div><p>Just curious.. if addViewListner() can be replaced
view.addEventListener in a project. Or would it cause a breach into
the normal flow or way through which Robotlegs functions ?</p></div>vishwas.gagranitag:robotlegs.tenderapp.com,2009-10-18:Comment/198305322012-10-19T20:28:50Z2012-10-19T20:28:50Zis addViewListener similar to view.addEventListner ? <div><p>From a mediator, it's good to use addViewListener() rather
than<br>
view.addEventListener().</p>
<p>By using addViewListener(), Robotlegs automatically removes the
listener<br>
when the mediator is destroyed, so you're not left with a lingering
event<br>
listener that's keeping things from getting garbage collected. If
you don't<br>
use addViewListener() then you'll want to override the
mediator's<br>
onRemove() method and put a call to view.removeEventListener() in
there.</p>
<p>I don't think this is what you meant, but if you were wondering
if you<br>
should call a mediator's addViewListener() method from another
class, I<br>
would recommend against it, for the same reason it's good to use
within the<br>
mediator. Then the decision of whether your listener is registered
or not<br>
will be linked to whether the mediator exists or not (which
generally<br>
corresponds to whether the view is on the stage or not).
Presumably<br>
something other than the mediator won't want its event listening to
be<br>
controlled by the lifecycle of the mediator.</p>
<p>Paul</p></div>Paul Robertsontag:robotlegs.tenderapp.com,2009-10-18:Comment/198305322012-10-19T21:05:03Z2012-10-19T21:05:03Zis addViewListener similar to view.addEventListner ? <div><p>just to add to what Paul said is that the same thing is true of
<code>addContextListener</code> you could just as well add a
listener to the superclass <code>eventDispatcher</code> except that
you would have to clean it up on the <code>onRemove</code>
hook.</p></div>neil