Instead of directly accessing the children, which could lead to complex code
which would be prone to failure and difficult to modify, try using a Facade
object, implemented as either a singleton or using injection (if you happen to
be using a framework which supports it). I recommend a singleton facade for
this purpose, since it is more decoupled. you can reference it as a simple
IEventDispatcher, eliminating the need to bind your child components to a
specific class definition.
listen for an event such as UPDATE_SUPER_TAB_CHILD_DATA:String =
"updateSuperTabChildData";
define the event to have "tabChildId:String" property in the constructor. then
you match the event.id against this.id and you determine if you need to act on
the event and listen for it in all children.
If there are too many children for this quick/dirty approach to be effective
you can use a more complex subscriber pattern, and use a singleton bus and have
the child "register" itself as a subscriber, providing a unique id (or
recycling subscriberObject.id - which would be the exact component you are
trying to locate below). then you can have a method in the bus class with the
prototype:
public function updateChildData(childID:String):void {
for each(var child:IVisualElement in subscribers) {
if(child.id == childID) {
child.dispatchEvent(new Event("updateYourData"));
break;
}
}
}
There are lots of ways to do it, but navigating from the top down to a specific
child is not recommended since the children may or may not be fully
constructed. I recommend that to ensure full subscription that you either use
an ActionScript class and instantiate and add them during the existing flex
lifecycle of the parent object, or if you must use an mxml for some reason,
expose an "initDataHandlers" public method and still create them in
actionscript and initDataHandlers on the child object and then add them as
children of the super grid.
I'm sure that one of or a combination of these recommendations will get you
right where you want to be.
Good luck.
David
> Date: Tue, 29 Oct 2013 21:09:11 -0400
> Subject: Getting SuperTabNavigator child
> From: [email protected]
> To: [email protected]
>
> Hi,
>
> I have several components (Box with DataGrids) added as children to
> SuperTabNavigator.
> Need to get a handle to such child component to refresh its DataGrid's data
> (or possibly to close it and open another one like that with new data).
>
> So how can I get a handle to the child of SuperTabNavigator?
>
> --
> Thank you in advance,
> Oleg.