We may have a slightly unusual setup, where the context parent-child relationship is not related to the display list. Each view is loaded into a ViewLoader, which sets up the view's context with the following extensions:
public function extend(context:IContext):void
{
context.install(
TraceLoggingExtension,
VigilanceExtension,
InjectableLoggerExtension,
ContextViewExtension,
EventDispatcherExtension,
DirectCommandMapExtension,
EventCommandMapExtension,
LocalEventMapExtension,
ViewManagerExtension,
StageObserverExtension,
MediatorMapExtension,
ViewProcessorMapExtension,
StageCrawlerExtension,
StageSyncExtension
).install( new ModularityExtension(false, true) );
context.configure( ContextViewListenerConfig );
var viewProcessor:IViewProcessorMap = context.injector.getInstance( IViewProcessorMap );
viewProcessor.map( IViewLoader ).toProcess( new MediatorCreator( ViewLoaderMediator ));
}
This all works fine. However, when two views are nested, and the parent is removed from the stage, I get the following error in the viewProcessor for the child view's context:
TypeError: Error #1006: value is not a function.
at robotlegs.bender.extensions.viewProcessorMap.impl::ViewProcessorFactory/runAllUnprocessors()[/Development/Projects/Robotlegs/robotlegs-framework/src/robotlegs/bender/extensions/viewProcessorMap/impl/ViewProcessorFactory.as:92]
at robotlegs.bender.extensions.viewProcessorMap::ViewProcessorMapExtension/beforeDestroying()[/Development/Projects/Robotlegs/robotlegs-framework/src/robotlegs/bender/extensions/viewProcessorMap/ViewProcessorMapExtension.as:72]
at MessageRunner/next()[/Development/Projects/Robotlegs/robotlegs-framework/src/robotlegs/bender/framework/impl/MessageDispatcher.as:152]
at MessageRunner/run()[/Development/Projects/Robotlegs/robotlegs-framework/src/robotlegs/bender/framework/impl/MessageDispatcher.as:135]
at robotlegs.bender.framework.impl::MessageDispatcher/dispatchMessage()[/Development/Projects/Robotlegs/robotlegs-framework/src/robotlegs/bender/framework/impl/MessageDispatcher.as:87]
at robotlegs.bender.framework.impl::LifecycleTransition/enter()[/Development/Projects/Robotlegs/robotlegs-framework/src/robotlegs/bender/framework/impl/LifecycleTransition.as:191]
at robotlegs.bender.framework.impl::Lifecycle/destroy()[/Development/Projects/Robotlegs/robotlegs-framework/src/robotlegs/bender/framework/impl/Lifecycle.as:173]
at robotlegs.bender.framework.impl::Context/destroy()[/Development/Projects/Robotlegs/robotlegs-framework/src/robotlegs/bender/framework/impl/Context.as:183]
at robotlegs.bender.extensions.contextView::StageSyncExtension/onRemovedFromStage()[/Development/Projects/Robotlegs/robotlegs-framework/src/robotlegs/bender/extensions/contextView/StageSyncExtension.as:92]
at flash.display::DisplayObjectContainer/removeChild()
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::$removeChild()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/framework/src/mx/core/UIComponent.as:7312]
at mx.core::UIComponent/removeChild()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/framework/src/mx/core/UIComponent.as:7219]
at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementRemoved()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/spark/src/spark/components/Group.as:1732]
at spark.components::Group/removeElementAt()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/spark/src/spark/components/Group.as:1479]
at spark.components::Group/removeAllElements()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/spark/src/spark/components/Group.as:1498]
at ViewLoader/applyViewImpl()
at ViewLoader/commitProperties()
at mx.core::UIComponent/validateProperties()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/framework/src/mx/core/UIComponent.as:8227]
at mx.managers::LayoutManager/validateProperties()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/framework/src/mx/managers/LayoutManager.as:605]
at mx.managers::LayoutManager/doPhasedInstantiation()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/framework/src/mx/managers/LayoutManager.as:821]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[/Users/justinmclean/Documents/ApacheFlexSDK/frameworks/projects/framework/src/mx/managers/LayoutManager.as:1188]
I have tried forcing the child to be removed before the parent, but that doesn't prevent the error.
The issue was caused by multiple mediators being mapped to each ViewLoader. When a Viewloader is nested twice, both ancestor Contexts would add the mapping. It was an easy fix to use the same instance of MediatorCreator
everywhere, which manages this itself.