Although a reference to your Flex app will show you have
app.appView and
app.loginPanel as properties, from a
display hierarchy standpoint, your LoginPanel is
not a child of the main app but
instead a child of the VBox called appView which is the only child of the main app:
<mx:VBox id="appView">
<loginComp:LoginPanel id="loginPanel" />
</mx:VBox>
Your actual display hierarchy is
app.appView.loginPanel. When you do a
app.removeChildAt(0) you're removing
appView.
This is a disparity between an MXML component which uses the 'id' property to reference all the child components it defines as direct sibling properties, regardless of their location in the display hierarchy, and Flash DisplayObject, which implements the display hierarchy and uses the 'name' property to reference children, which are not properties but array elements.
Its confusing, because
app.appView.loginPanel is
not valid object notation because loginPanel
is not a property of appView, even though
it is a child.
To test this, in your MainApp, add this:
<mx:Script>
<![CDATA[
public function initApp():void
{
// The following will fail with:
// ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller
// this.removeChild(loginPanel);
// this will work because the loginPanel is really a child of appView
this.appView.removeChild(loginPanel);
}
]]>
</mx:Script>
and in the Application tag add:
creationComplete="initApp()"
and comment out your facade.startup for now.
Run this and you'll see your loginPanel disappear.
One side note here: You plan to add other component definitions to your main application, but that nested VBox is not needed in this current implementation, and in fact slows the performance of your Flex app because it adds an unnecessary sizing and layout pass. You can instead just set your Application to
layout="vertical". Never make your first and only container within an Application be a Canvas, HBox or VBox, because the Application is all of these.
So, given what we know now about your display hierarchy, and assuming you leave the appView VBox where it is the following change to the mediator should work:
override public function handleNotification( note:INotification ):void
{
case ApplicationFacade.REMOVE_LOGIN_PANEL:
app.appView.removeChild(loginPanel);
break;
case ApplicationFacade.ADD_USER_MGMT_CTNR:
app.appView.addChild(note.getBody() as UserManagementContainer);
break;
}
-=Cliff>