Regarding the creation of MXML components in commands

mdw1980's Avatar


11 Jan, 2010 04:15 PM

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.

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.

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?

  1. Support Staff 1 Posted by Till Schneidere... on 11 Jan, 2010 04:20 PM

    Till Schneidereit's Avatar

    Can't you add a mediator for SomePanel? In that mediator, you could
    call "setDefaultValues" in the "onRegister" hook, which gets invoked
    after CreationComplete to solve exactly your problems with
    initialization order.

  2. 2 Posted by mdw1980 on 11 Jan, 2010 04:24 PM

    mdw1980's Avatar

    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.

  3. Till Schneidereit closed this discussion on 02 Mar, 2010 12:55 PM.

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

Keyboard shortcuts


? 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