Question

In my application I have a viewstack which I am changing via actionscript using the selectedChild attribute. The problem I run into is that I want to call a method in the component that is now the selected child in the viewstack, right after I assign it to be the child it gives me a "Cannot access a property or method of a null object reference." Is there some way that I can make this work without changing the creationPolicy to all?

Actionscript:

    public function displayTaskDashboard(evt:Event):void
    {
    pm_viewstack.selectedChild = nc_taskDashboard;
taskDashboard.populateTasks(Globals.currentProject.Project_ID);
}

MXML:

  <mx:ViewStack id="pm_viewstack" creationPolicy="auto">
    <s:NavigatorContent id="nc_projectDashboard">
        <components:ProjectDashboard/>
    </s:NavigatorContent>
    <s:NavigatorContent id="nc_taskDashboard">
        <components:TaskDashboard id="taskDashboard" />
    </s:NavigatorContent>
    <s:NavigatorContent id="nc_taskWizard">
        <components:TaskWizard id="taskWizard" />
    </s:NavigatorContent>
</mx:ViewStack>
Was it helpful?

Solution

Try to call .validateNow() or .validateDisplayList() method on your ViewStack instance (pm_viewstack.validateNow() or pm_viewstack.validateDisplayList()) before accesing its child. But I'm not sure if it would help with child creation policy.

OTHER TIPS

The problem is ViewStack doesn't create children until they are first assigned to selectedChild. This saves memory because the user might not access every possible page during runtime. This is the default behavior. Most people simply change the creationPolicy to pre-instantiate all children thus nullifying the memory savings. The alternative is to register a creationComplete event listener on each child. That way you can resume your algorithm once the child has been created. That maintains the memory savings you get, and allows you to resume after the child has been created. Things to keep in mind is that it's not run every time selectedChild is assigned too. But, you can easily work around that with some simple if checks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top