Passing Event payload to Command

roelof's Avatar


17 Sep, 2016 11:50 AM


With reference to the following discussion:

I am passing Event with Payload and mapping it to Command in the Context, but for some reason the payload does not arrive at my Command. I am injecting the Event into the Command:

public var fileLoadedEvent:FileLoadedEvent;

override public function execute():void
var xmlFile:XML = fileLoadedEvent.file;

The event is fired from a service that loads a XML file from the host filesystem. When I put breakpoints in the service and/or event, the payload does show in the Variables windows (FlashBuilder Debug), but when it executes above assignment, then it bombs out, because payload is not present.

Please advise.

  1. Support Staff 1 Posted by Ondina D.F. on 18 Sep, 2016 08:15 AM

    Ondina D.F.'s Avatar

    Hi roelof,

    [INJECT] should be [Inject]

    Take a look at the 2 most common problems pertaining to metadata:

    Look at how the eventCommandMap works and how to map your events to a command:

    In robotlegs 2 you don't need to extend a command class. Any class having a public method execute() and mapped correctly to an event will be recognized by the framework as being a Command.

    I gave you an example of an Event class and a Command class in one of our previous discussions:

    Hier a modified version with an injected event:

    public class SomeCommand
        public var someEvent:SomeEvent;
        public function execute():void
        //hier you can access:
        // someEvent.somePayload

    If none of the above solves your problem, I'll need to see:

    • how are you mapping the event to the command
    • how is your event class looking, i.e. how are you defining the payload inside the event class ( your 'file' property)

    Have you tried to send another type of payload to the command, say, a simple String instead of an XML?
    Have you tried to access the loaded XML inside of your service class? Does it work there?


  2. 2 Posted by roelof on 18 Sep, 2016 04:27 PM

    roelof's Avatar

    [Inject] seems to have solved the problem, apologies for wasting your time; it was a silly mistake that I shouldn't have missed.

  3. Support Staff 3 Posted by Ondina D.F. on 19 Sep, 2016 10:41 AM

    Ondina D.F.'s Avatar

    Ah, don't worry :)
    This kind of mistakes are easy to overlook, especially because there are no warnings, no errors thrown at compile- or runtime to give us a hint about what's wrong.

    I wish you happy coding!

  4. Ondina D.F. closed this discussion on 19 Sep, 2016 10:41 AM.

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