Create views dynamically (best practices)
Hi, I'm starting with Robotlegs, and after reading a lot and seeing the diagram (http://www.robotlegs.org/diagram/) I can't see clearly how can we create and delete views dynamically.
Do we need a commnad and inside it we create a new view map it to a mediator and then add to contextView displayList?
What are the best practices for this?
Thanks!
Enrique.
Comments are currently closed for this discussion. You can start a new one.
2 Posted by timkindberg on 03 Nov, 2010 04:23 PM
In the context map the View Class to the Mediator Class. Then anytime at view of that Class type is ADDED_TO_STAGE, the mediator class will automatically be created with it. When it is REMOVED_FROM_STAGE, the mediator will be destroyed along with it.
3 Posted by rdevitt on 06 Nov, 2010 01:05 AM
Please forgive a Robotlegs newbie if this is obvious or answered elsewhere.
Related to the original question, how do I get the dynamically created child mediator to handle events from a corresponding child model instance only?
4 Posted by Abel de Beer on 06 Nov, 2010 10:03 AM
@rdevitt:
It is common practice to create custom Event classes for this purpose. For example, your ExampleModel could dispatch events of the type ExampleModelEvent. Your ExampleMediator should then register listeners for these events.
If you use the AS3Signals library you have two options:
Create custom Signal classes, for example ExampleModelRegisteredSignal, and then [Inject] the signals into your Mediator.
Expose your Model's signals by making them public and then [Inject] the Model into your Mediator, registering listeners for its signals.
Stray closed this discussion on 13 Feb, 2011 03:06 PM.