Create views dynamically (best practices)

Enrique's Avatar

Enrique

03 Nov, 2010 04:19 PM

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.

  1. 2 Posted by timkindberg on 03 Nov, 2010 04:23 PM

    timkindberg's Avatar

    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.

  2. 3 Posted by rdevitt on 06 Nov, 2010 01:05 AM

    rdevitt's Avatar

    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?

  3. 4 Posted by Abel de Beer on 06 Nov, 2010 10:03 AM

    Abel de Beer's Avatar

    @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.

  4. Stray closed this discussion on 13 Feb, 2011 03:06 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac