Hi,
With reference to the following discussion: http://knowledge.robotlegs.org/discussions/robotlegs-2/15290-mapping-event-with-second-type-to-command-is-not-working
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:
[INJECT]
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 Posted by Ondina D.F. Support staff on 18 Sep, 2016 08:15 AM
Hi roelof,
[INJECT] should be [Inject]
Take a look at the 2 most common problems pertaining to metadata:
https://github.com/robotlegs/robotlegs-framework/wiki/Common-Proble...
https://github.com/robotlegs/robotlegs-framework/wiki/Common-Proble...
Look at how the eventCommandMap works and how to map your events to a command:
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...
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:
http://knowledge.robotlegs.org/discussions/robotlegs-2/14800-displa...
Hier a modified version with an injected event:
If none of the above solves your problem, I'll need to see:
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?
Ondina
#2 Posted by roelof on 18 Sep, 2016 04:27 PM
[Inject] seems to have solved the problem, apologies for wasting your time; it was a silly mistake that I shouldn't have missed.
#3 Posted by Ondina D.F. Support staff on 19 Sep, 2016 10:41 AM
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!
Ondina D.F. closed this discussion on 19 Sep, 2016 10:41 AM.