tag:knowledge.robotlegs.org,2009-10-18:/discussions/solutions/22-alternate-solution-for-inavigationcontent-mediatation-ie-viewstack-accordian-tabnav-etcRobotlegs: Discussion 2012-08-27T10:38:43Ztag:knowledge.robotlegs.org,2009-10-18:Comment/157831852012-05-04T20:33:59Z2012-05-04T20:34:00Zalternate solution for INavigationContent mediatation (ie ViewStack, Accordian, TabNav, etc)<div><p>I noticed it was brought up "eons" ago back in all of 2010, but
I thought I'd throw my hat out there if anyone wants to take a
look. As suggested by the authors, to create a mediator for the
sub-children of the container, in some cases it makes more sense to
create the mediator at the child level - but this introduces the
issue of the children of the view aren't available just yet.</p>
<p>The code extends the basic mediator and looks for the the
deferredContentCreated flag, and if it's not found then add a
listener for the FlexEvent.CONTENT_CREATION_COMPLETE.</p>
<p>(btw, RL rocks) ;)</p>
<pre>
<code>package
{
import flash.events.Event;
import mx.core.INavigatorContent;
import mx.core.UIComponent;
import mx.events.FlexEvent;
import org.robotlegs.mvcs.Mediator;
/**
* This mediator is intended for INavigatorContent / Spark.NavigatorContent
* views - when created, unless it is the current visible item based on it's
* contentCreationPolicy - it will only create the outer shell of the view.
*
* So we check the associated view and if it is deferred - we halt
* the onRegister process until it has triggered the FlexEvent.CONTENT_CREATION_COMPLETE
* event.
*/
public class NavigatorContentMediator extends Mediator
{
public function NavigatorContentMediator()
{
super();
}
override public function onRemove():void
{
super.onRemove();
view.removeEventListener(FlexEvent.CONTENT_CREATION_COMPLETE, onContentCreationComplete);
}
override protected function onCreationComplete(event:Event):void
{
if (view.deferredContentCreated) super.onCreationComplete(event);
else
{
view.removeEventListener(event.type, onCreationComplete);
view.addEventListener(FlexEvent.CONTENT_CREATION_COMPLETE, onContentCreationComplete);
}
}
protected function onContentCreationComplete(event:FlexEvent):void
{
view.removeEventListener(FlexEvent.CONTENT_CREATION_COMPLETE, onContentCreationComplete);
super.onCreationComplete(event);
}
/**
* A rare case where we want a private property to the view - this allows us
* to ensure it's of the interface we want without enforcing the same interface
* in super mediators - allowing them to type cast a protected or private property
* as the concrete view it mediates.
*/
private function get view():INavigatorContent
{
return getViewComponent() as INavigatorContent;
}
}
}</code>
</pre></div>Mike