Flex TitleWindow.addChild 删除原始对象

发布于 2024-08-15 12:27:43 字数 1022 浏览 10 评论 0原文

在我的应用程序中,我有一个图表,我想在单击时在 TitleWindow 中显示该图表。

        var win:TitleWindow = PopUpManager.createPopUp(this, TitleWindow, false) as TitleWindow;
        win.addChild(myChart);
        PopUpManager.bringToFront(win);

它确实将图表放置在显示的标题窗口中,但它从父级中删除了原始图表。然后,当标题窗口关闭时,我的图表就消失了。我不知道如何克隆图表——我尝试过的所有方法都失败了——而且我不知道为什么会发生这种情况。

解决方案:

  public var barChart:BarChart;
  public function onClick(e:Object):void
  {
    barChart = (e as BarChart);
    if(barChart != null)
    {
        var win:MyWindow = PopUpManager.createPopUp(this, MyWindow, false) as MyWindow;
        PopUpManager.centerPopUp(win);

    }
  }

// ... MyWindow.mxml ...

var _parent:Object;
private function creationComplete(e:Event):void
{
    bChart = parentApplication.barChart;
    _parent = bChart.parent;
    this.addChild(bChart);
}

private function onMyWindowClose(evt:CloseEvent):void {
    _parent.addChild(bChart);
    PopUpManager.removePopUp(this);
}

In my application, I have a chart that I want to display in a TitleWindow when clicked on.

        var win:TitleWindow = PopUpManager.createPopUp(this, TitleWindow, false) as TitleWindow;
        win.addChild(myChart);
        PopUpManager.bringToFront(win);

It does indeed place the chart in the titlewindow that shows up, but it removes the original chart from the parent. Then, when the titlewindow is closed, my chart is simply gone. I can't figure out how to clone the chart -- all the methods I've tried failed -- and I have no idea why this is happening.

Solution:

  public var barChart:BarChart;
  public function onClick(e:Object):void
  {
    barChart = (e as BarChart);
    if(barChart != null)
    {
        var win:MyWindow = PopUpManager.createPopUp(this, MyWindow, false) as MyWindow;
        PopUpManager.centerPopUp(win);

    }
  }

// ... MyWindow.mxml ...

var _parent:Object;
private function creationComplete(e:Event):void
{
    bChart = parentApplication.barChart;
    _parent = bChart.parent;
    this.addChild(bChart);
}

private function onMyWindowClose(evt:CloseEvent):void {
    _parent.addChild(bChart);
    PopUpManager.removePopUp(this);
}

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

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

发布评论

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

评论(2

吃→可爱长大的 2024-08-22 12:27:43

当您执行 addChild 时,对象将被重新设置父级,正如 Simon 所说,一个 DisplayObject 不能属于两个父级。如果打开弹出窗口时不能同时看到两个图表,您可以在打开弹出窗口之前保存子父项和索引,并在关闭弹出窗口时恢复子项状态。

打开之前

myChartParent=myChart.parent;
myChartIndex=myChartParent.getChildIndex(myChart);

关闭时

myChartParent.addChildAt(myChartIndex);

但是如果您想查看两个图表,您将必须创建两个图表实例。

When you do an addChild the object is reparented, as said Simon one DisplayObject can't belong to two parent. If is s not a problem to not seeing two chart in the same time when you open your popup, you can before you open the popup save the child parent and index, and when you close the popup restore the child state.

before opening

myChartParent=myChart.parent;
myChartIndex=myChartParent.getChildIndex(myChart);

when closing

myChartParent.addChildAt(myChartIndex);

But if you want to see two chart you will have to create two chart instance.

云裳 2024-08-22 12:27:43

我还没有找到支持它的文档,但我相信 Flash UI 组件只能有一个父组件。当您调用 addChild() 时,我怀疑控件的起源发生了变化,并且它从另一个窗口中消失了。由于起源已经改变,当新的 TitleWindow 消失时,它将被垃圾收集。

我认为我在你的位置上要做的是将图表抽象为它自己的控件,这样你就不必重复代码,在常规窗口和弹出窗口中使用相同的控件,并在createPopUp 调用。

I haven't managed to find documentation to support it, but I believe that a Flash UI component can only have a single parent. When you call addChild() I suspect that the parentage of the control changes and it disappears from the other window. Since the parentage has changed it will get garbage collected when the new TitleWindow disappears.

What I think I would do in your position would be to abstract the chart out to its own control so you don't have to duplicate code, use the same control in your regular window and your popup, and pass the data to it after the createPopUp call.

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