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: Flex - When to register mediators to states of a component ?  (Read 7452 times)
mattb
Newbie
*
Posts: 7


View Profile Email
« on: January 25, 2009, 03:24:35 »

Hi, we have just started with FLex and PureMVC and we are have come across an issue regarding registering mediators to states of a component.

An MXML component has various states.  Each state is another MXML that is wrapped in an AddChild tag.  Each state component contains buttons, input fields, labels etc and has properties that are binded to the labels, tooltips etc.

A Mediator is instantiated for the main component and registered with the facade.
Each state component has a mediator who's constructor sets the binded properties.

The issue we have is WHEN should register the mediators for each state.?

If we register the mediator for each state view at the same time as we register the mediator for the main component we get null object reference errors at run time.  I'm not sure of the null object is the the state, or the binded properties within the states view.

The way we have got round it is to wait for the "creationComplete" event of each state component to fire, then send that to the Main component mediator. 

This then sends a note to trigger a command that will register the appropriate mediator for the state component that has just loaded.

However we end up with an extra command that checks the note for which state view has just loaded and then register its Mediator and send a note to set the binded properties for the labels etc in the view.


I was wondering if we are missing something, is there a way to register these mediators without having to have the creationComplete events and extra commands to handle them?


Should we simply have the "creationComplete" event trigger a handler in the mediator that then registers its mediator and NOT have a command that does this?

Is there a totally different approach?


I can post some examples if that is needed.

Thanks in advance, Matt.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: January 28, 2009, 07:46:09 »

You can skip the command if you wish and have the Mediator do the registrations, similar to the way the Slacker demo adds Mediators for the children of the viewstack that are subject to delayed instantiation.

But with mx:States, you need to remember that the components are destroyed on state change, and so you also need to remove the associated Mediators for components. You can do this by making those Mediators listen to the removed events sent by their view components. When the mediator hears that event, it removes itself with facade.removeMediator(this.getMediatorName()) and then nulls its viewComponent reference. Then they both get GC'd.

-=Cliff>
Logged
Pages: [1]
Print