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: Where to instantiate runtime UI components?  (Read 7796 times)
llewynx
Newbie
*
Posts: 2


View Profile Email
« on: May 14, 2008, 08:42:49 »

Hi,

I'm working on an app (pure AS3, using FlexBuilder but not Flex) where parts of the ui will be created at runtime when a notification from a server is received that data needed for the ui is received. I have a base ui class that has it's own mediator, but no other ui components. When all is finished loaded from the server, a notification is sent out ("createUI") by a proxy, but here comes my problem - where to instantiate all my ui components so i can register their mediators? My thought was to have a CreateUiCommand that register the mediators, but I feel uncomfartable creating the ui components in there. The base ui class own mediator will probably handle notifications for laying out the created components when they are all done, but where to create them? In a proxy or in a command, or maybe in the base ui's mediator? I cannot have them in the base ui class since they can't be instantiated at startup. There are around 10 components that have to be created at runtime...

In short, where to put this code:
:
var dataFromServer:Object = notification.getBody();
var myComponent:MyComponent = new MyComponent( dataFromServer );
registerMediator( new MyComponentMediator( myComponent ) );

Do I make any sense? :P

Thanks!
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: May 14, 2008, 10:56:46 »

You could register the mediator without a view component and then have it respond to a given notification by creating that view component.

Of course that view component would then need to make its way into the display hierarchy, so you might have to send another notification once its created that carries a reference to the newly created display component. The mediator of the part of the view that this needs to become a child of would then respond to that notification by doing something like an addChild on its view component, passing the reference to the newly created component. That's the extent of the second mediator's interaction with that component, though, and the original mediator places the listeners on the new component and mediates for it.

Hope that makes sense,
-=Cliff>
Logged
llewynx
Newbie
*
Posts: 2


View Profile Email
« Reply #2 on: May 15, 2008, 05:04:44 »

Hi Cliff,

Thanks for the tip. I am now registering the mediators without view components and letting the mediators themselves create their components upon received notification, and then sending them on in another notification (ADD_COMPONENT) that the main mediator is listening to. Works like a charm!

And thanks for a great framework! :)
Logged
Pages: [1]
Print