Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Notification received when child components aren't created yet  (Read 3455 times)
codecraig
Full Member
***
Posts: 23


View Profile Email
« 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?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 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>
Logged
codecraig
Full Member
***
Posts: 23


View Profile Email
« Reply #2 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
Logged
Pages: [1]
Print