tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/36-regarding-the-creation-of-mxml-components-in-commandsRobotlegs: Discussion 2018-10-18T16:35:07Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/8363742010-01-11T16:15:10Z2010-01-11T16:15:10ZRegarding the creation of MXML components in commands<div><p>So I have this app, right? In my app I have a view component
that is created and removed upon certain user input. So for
instance, when a user clicks a particular button, the
AppEvent.ShowSomePanel event is dispatched by a mediator and a
reference to a display container is passed along with it. This
event is mapped to the ShowSomePanelCommand. When the command is
executed it creates an instance of SomePanel ( new SomePanel() )and
then adds it to the display container ( event.container.addChild(
panel ) )in the event object.</p>
<p>In the SomePanel component, there are some input fields that I
want to populate with default values that are stored in a model. As
of now, I'm passing those values into the component through a
"setDefaultValues" method and storing them in a couple class
variables. I am then setting the input field values upon the
CreationComplete event to ensure the input fields are actually
there.</p>
<p>I feel as if this makes my component a little messy because the
class variables that i'm storing the values in are never used again
after the component is created. Is there a better way to set the
properties of the nested input fields without having to store them
and wait until they are created?</p></div>mdw1980tag:robotlegs.tenderapp.com,2009-10-18:Comment/8363742010-01-11T16:20:54Z2010-01-11T16:20:54ZRegarding the creation of MXML components in commands<div><p>Can't you add a mediator for SomePanel? In that mediator, you
could<br>
call "setDefaultValues" in the "onRegister" hook, which gets
invoked<br>
after CreationComplete to solve exactly your problems with<br>
initialization order.</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/8363742010-01-11T16:24:47Z2010-01-11T16:24:47ZRegarding the creation of MXML components in commands<div><p>Oh man, now I feel stupid. I guess thats one way to go. For some
reason I was feeling as if injecting a model into my mediator would
be a bad move. But now I see from the best practices doc that if I
do this, it should be done via an interface.</p></div>mdw1980