injection into command doesn't seem to be working

Chris Sheffield's Avatar

Chris Sheffield

08 Apr, 2010 04:01 PM


I'm sure I'm just doing something wrong. I'm still learning both Flex and Robotlegs. So please be patient with me. :-)

In my context, I have this code:

var selectedEmployee:Employee = new Employee();
injector.mapValue(Employee, selectedEmployee, "selectedEmployee");

Then in my app's mediator I have this:

public var selectedEmployee:Employee;

And then in an event handler, also in my app's mediator, I do this:

private function onSelectionChange(e:SelectEmployeeEvent):void
    selectedEmployee = e.employee;

All is well, and the selectedEmployee object gets set with the properties and everything that it should. So now, at some point in a command, I want to be able to access this exact same selectedEmployee object. So in a command I have:

public var selectedEmployee:Employee;

The command now has a selectedEmployee object, but it is not the same instance as accessed in the app's mediator, as all of its properties are null.

What am I doing wrong? Is this even the correct way to go about things? From the examples in the Best Practices doc, it seems like this should work. Any help would be appreciated.


  1. Support Staff 1 Posted by Shaun Smith on 08 Apr, 2010 06:51 PM

    Shaun Smith's Avatar

    Hi Chris,

    What's happening here is that the same instance IS being injected into your Mediator and Command, BUT in the event handler you are changing the Mediator's reference to point to a different instance - doing so won't change any other references to the original instance.

    Instead of dealing with a single Employee instance you could create an EmployeeModel that has a selectedEmployee property. Inject the model into your Mediator and Command and manipulate the selectedEmployee property as needed.

    Hope that helps!

  2. 2 Posted by Chris Sheffield on 08 Apr, 2010 07:31 PM

    Chris Sheffield's Avatar

    Wow, Shaun. Thank you. I knew it would be something simple. And it turned out to be my misunderstanding of assignments in Flex. :-) I just assumed that I could copy one instance of an object into another by using the assignment operator. Apparently that's not the case. All is well now. Thanks again.

  3. Support Staff 3 Posted by Shaun Smith on 08 Apr, 2010 07:48 PM

    Shaun Smith's Avatar

    Cool, no problemo :)

  4. Shaun Smith closed this discussion on 08 Apr, 2010 07:48 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