tags:

views:

70

answers:

2

I'm extending a Panel to build a custom component. Without knowing what this will contain later, how can I add a method to temporarily hide all contents and displaying an internal object (which is normally invisible) instead?

That is, is there a better way than

for each (var ui:DisplayObject in this.getChildren()) {
  ui.visible = false;
}

What I would love to do is swapping out the root content pane, but I don't know how to access it. Like this:

this._tempStore = this.removeChild(this.rootContentPaneObject);
this.rootContentPaneObject = this._myTemporaryReplacement;

Effectively, I'm trying to build a component which acts as a dropin replacement for a Panel but which behaves similar to a ViewStack.

A: 

You seem to be looking for Container.contentPane. Note that it is mx_internal, so we are diving into Flex internals here (at your own risk...).

import mx.core.mx_internal;
...
    this.mx_internal::contentPane.visible = false;

Next question is then how do you add children which are still visible (not in the contentPane). You might have to use Container.rawChildren for that.

Wouter Coekaerts
I also found that digging into the source code, but I'd rather avoid that path. Adding to the chrome (the "internal" children) via `rawChildren` works well and is well documented, for example in "Flex 3: Training from the source", available at Safari Books Online.
Hanno Fietz
+1  A: 

maybe it might be easer to place a ViewStack within your Panel and use the stack to show / hide the appropriate content.

Jon.Stromer.Galley
Yes, that was my first approach, but it opens up a whole new can of worms. It means you have to override all methods that deal with children to delegate them to the `ViewStack`'s child that takes the user-added subcomponents. I might eventually do it anyway, but my first attempt brought up a number of weird errors.
Hanno Fietz