Search code examples
actionscript-3apache-flexflex-spark

How do I respond to a NavigatorContent being selected in a View Stack


I have view stack in a app like so:

<mx:ViewStack id="viewStack" left="0" right="0" top="0" bottom="0">
    <views:LoginView top="0" bottom="0" right="0" left="0" id="loginView"/>
    <views:MainHomeView top="0" bottom="0" right="0" left="0" id="childSelectionView"/>
    <views:MainHomeView top="0" bottom="0" right="0" left="0" id="mainEvalView"/>
</mx:ViewStack>

When an event is fired, I call viewStack.selectedChild = childSelectionView

My question is how do I code a listener for the NavigatorConent being selected?

Here is what I try to do:

<?xml version="1.0" encoding="utf-8"?>
<s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:local="*" xmlns:mx="library://ns.adobe.com/flex/mx" 
    creationComplete="init()">

    <fx:Script>
        <![CDATA[
        private function init():void
        {
            // Do something here
            advanceButton.visablitiy = false;
        }
    ]]>
</fx:Script>
<s:VGroup>

    <s:HGroup>
        <s:Button label="Advance" id="advanceButton" />
    </s:HGroup>
</s:VGroup>

I know that all the NavigatorConent's dispatch a creationComplete event on the application start, but their childrent aren't created yet. How did I respond to the on selectedChild change to self?


Solution

  • Sometimes it pays to poke around a bit, literally the question right before yours is exactly in the same problem domain. Use the FlexEvent.CONTENT_CREATION_COMPLETE event.

    See Flex Error #1009: Cannot access a property or method of a null object reference