Flex:视图堆栈更改后调用方法

发布于 2024-12-18 19:42:16 字数 939 浏览 1 评论 0原文

在我的应用程序中,我有一个视图堆栈,我正在使用 selectedChild 属性通过动作脚本更改它。我遇到的问题是,我想调用组件中的一个方法,该组件现在是视图堆栈中选定的子组件,在我将其分配为子组件之后,它给了我一个“无法访问空对象的属性或方法”参考。”有什么方法可以让我在不改变全部creationPolicy的情况下完成这项工作吗?

动作脚本:

    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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

束缚m 2024-12-25 19:42:16

在访问其子级之前,尝试在 ViewStack 实例上调用 .validateNow() 或 .validateDisplayList() 方法(pm_viewstack.validateNow() 或 pm_viewstack.validateDisplayList())。但我不确定这是否有助于儿童创造政策。

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.

随心而道 2024-12-25 19:42:16

问题是 ViewStack 在子项首次分配给 selectedChild 之前不会创建它们。这可以节省内存,因为用户可能不会在运行时访问每个可能的页面。这是默认行为。大多数人只是简单地更改creationPolicy来预先实例化所有子项,从而抵消了内存节省。另一种方法是在每个子项上注册一个creationComplete 事件侦听器。这样,一旦创建了子进程,您就可以恢复您的算法。这会保留您获得的内存节省,并允许您在子级创建后恢复。需要记住的是,它并不是每次分配 selectedChild 时都会运行。但是,您可以通过一些简单的 if 检查轻松解决这个问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文