tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/794-onremove-function-not-called-fast-enoughRobotlegs: Discussion 2014-04-19T18:08:44Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/260006102013-03-22T13:05:27Z2013-03-22T16:25:47ZonRemove function not called fast enough<div><p>Hey Valley,</p>
<p>First of all, sorry for the late response.</p>
<p>That’s a bit tricky. When using effects, components get
re-parented. removedEffect causes the components to be first
removed from stage, then added to the stage and then removed
again.<br>
So, in your case by the time you click fast on a new thumbnail a
new view is added to the stage, while the old one hasn’t
finished transitioning and its mediator hasn’t been destroyed
yet.</p>
<p>A workaround could be the following:</p>
<p>In the DetailsView you add events handlers for
EffectEvent.effectEnd.</p>
<pre>
<code>protected function removedEffect_effectEndHandler(event:EffectEvent):void
{
removedCompletely = true;
}
protected function addedEffect_effectEndHandler(event:EffectEvent):void
{
dispatchEvent(new SomeEvent(SomeEvent.VIEW_ADDED, this.name));
}</code>
</pre>
<p>DetailsMediator</p>
<pre>
<code>override public function onRegister():void
{
addViewListener(SomeEvent.VIEW_ADDED, onViewAdded, SomeEvent);
}
private function onViewAdded(event:SomeEvent):void
{
eventMap.unmapListener(view, SomeEvent.VIEW_ADDED, onViewAdded, SomeEvent);
dispatch(new SomeEvent(SomeEvent.VIEW_ADDED));
}
override public function onRemove():void
{
if(view.removedCompletely)
dispatch(new SomeEvent(SomeEvent.VIEW_REMOVED));
}</code>
</pre>
<p>When addedEffect ends, you dispatch an event, say,
SomeEvent.VIEW_ADDED.<br>
DetailsMediator listens for it and re-dispatches it:</p>
<p>ThumbsMediator listens for SomeEvent.VIEW_ADDED and sets
thumbsContainer.enabled to true, which was set to false in
ThumbsView when a thumbnail was clicked to prevent clicking on
other thumbs while a DetailView is about to be added.</p>
<p>If you want to add the new view first after the old one has been
removed from stage, you can listen to SomeEvent.VIEW_REMOVED,
dispatched by the DetailsView first after the removedEffect has
finished.</p>
<p>ThumbsMediator</p>
<pre>
<code>override public function onRegister():void
{
addContextListener(SomeEvent.VIEW_ADDED, onViewAdded, SomeEvent);
addContextListener(SomeEvent.VIEW_REMOVED, onViewRemoved, SomeEvent);
}
private function onViewAdded(event:SomeEvent):void
{
view.thumbsContainer.enabled=true;
}
private function onViewRemoved(event:SomeEvent):void
{
view.addAwaitingView();
}</code>
</pre>
<p>ThumbsView</p>
<pre>
<code>protected function addDetailView(event:MouseEvent):void
{
thumbsContainer.enabled=false;
// var viewToAdd:SomeViewToAdd = new SomeViewToAdd();
[Edit]
var viewToAdd:DetailsView = new DetailsView ();
if (detailsContainer.numElements==0)
{
detailsContainer.addElement(viewToAdd);
return;
}
if (awaitingView.indexOf(viewToAdd) == -1)
{
awaitingView.push(viewToAdd);
detailsContainer.removeAllElements();
}
public function addAwaitingView():void
{
if (awaitingView.length > 0)
{
detailsContainer.addElement(awaitingView[0]);
awaitingView = [];
}
}</code>
</pre>
<p>Does this help?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/260006102013-03-22T14:47:50Z2014-04-19T18:08:43ZonRemove function not called fast enough<div><p>Hi Ondina,</p>
<p>no problem, thanks for answering.<br>
Speaking clear this means when DetailsMediator dispatches the
VIEW_REMOVED Event in onRemove() the ThumbsMediator receives that
one (i hope the onRegister() function has already been passed so
that context listener is ready) and can then check if the user
meanwhile has already clicked on another thumbnail (stored in
awaitingView list) which can then be served.<br>
Clever idea. I will test this.<br>
Hopefully when i dispatch the VIEW_REMOVED Event at last in
onRemove() there isn't another time delay for really removing the
DetailsMediator so that the new details request will be correctly
served.</p>
<p>Thanks so far, i let you know if that worked.<br>
valley</p></div>rivella50tag:robotlegs.tenderapp.com,2009-10-18:Comment/260006102013-03-22T14:55:24Z2013-03-22T14:55:24ZonRemove function not called fast enough<div><p>You’re welcome! Yes, try it out, and please let me know
how it goes :)</p>
<p>Oh, now I see this line in my code snippet:<br>
var viewToAdd:SomeViewToAdd = new SomeViewToAdd();</p>
<p>It has to be<br>
var viewToAdd:DetailsView = new DetailsView ();</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/260006102013-03-28T17:12:51Z2013-03-28T17:12:51ZonRemove function not called fast enough<div><p>I guess this is resolved as well, right?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/260006102013-03-28T21:12:15Z2014-04-19T18:08:44ZonRemove function not called fast enough<div><p>I couldn't test it yet, but it sounds promising. So yes, you can
close it.<br>
As soon as i have time i will try it.</p>
<p>Thank you.<br>
valley</p></div>rivella50tag:robotlegs.tenderapp.com,2009-10-18:Comment/260006102013-03-29T09:20:44Z2013-03-29T09:20:44ZonRemove function not called fast enough<div><p>No problem!</p></div>Ondina D.F.