PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: codecraig on October 24, 2008, 05:18:30



Title: Notification received when child components aren't created yet
Post by: codecraig on October 24, 2008, 05:18:30
I have a view that extends VBox and contains a TabBar and a custom component.  The Mediator for this view (we'll call the view, FooView and FooViewMediator) receives a notification, which causes FooViewMediator to invoke FooView.update( items:ArrayCollection );

The 'update' method in FooView looks like:
:
<mx:Script>
  [Bindable] private var dpItems:ArrayCollection;

  public function update( items:ArrayCollection ) : void
  {
      dpItems = items;
     
      var index:int = tabBar.selectedIndex;

       // do stuff with the index
  }
</mx:Script>

<mx:TabBar id="tabBar" dataProvider="{dpItems}" />

The error I get is when I try and get the selectedIndex of the tabBar inside the 'update' method because 'tabBar' is still null.  I need the index to do something else in the view, however, the other custom component in the view is also still null.

I'm not sure how best to handle this.  I mean the FooView is not null which is how I was able to create the FooViewMediator. But now that the mediator is up it gets notifications, but it's child components in the FooView aren't ready. 

Suggestions?


Title: Re: Notification received when child components aren't created yet
Post by: puremvc on October 25, 2008, 04:41:08
The whole story here began with '... recieves a notification causing update to be called on view component' and ends with '... children aren't ready yet' this tells me you're getting the cart before the horse somewhere.

There's not enough context to go on here, but I'll take a guess at what could be happening.

If your model prep has fired off an async call that came back before the children of this view are ready, then you should listen for the view to be ready before triggering the service call.

-=Cliff>


Title: Re: Notification received when child components aren't created yet
Post by: codecraig on October 25, 2008, 07:40:20
yea, i realize there wasn't enough context, but the short story is I ended up adding a FlexEvent.CREATION_COMPLETE listener to the view, then taking action.

thanks