Mediator dispatching en event, however Command is not called
I have a weird issue, one of my events, event though it is mapped to a command in the context, does not function. Let me explain my flow briefly.
I have a MapEditorContext
, in which I map the
event:
commandMap.mapEvent ( MapEditorEvent.TILESET_SELECTION_CHANGE,
SetSelectedTilesetCommand,
MapEditorEvent,
false
);
In the TilesetsMediator
, there is a point where the
event is dispatched:
private function redispatchEventHandler(event:MapEditorEvent):void
{
trace("\n", this, "--- redispatchEventHandler ---");
trace("\t", "event: " + (event));
// traces event: [Event type="TILESET_SELECTION_CHANGE" bubbles=false cancelable=false eventPhase=2]
trace("\t", "event is MapEditorEvent: " + (event is MapEditorEvent));
// traces event is MapEditorEvent: true
dispatch(event);
}
On the side of the SetSelectedTilesetCommand
, it
seems like it's never called at all...
override public function execute():void
{
trace("\n", this, "--- execute ---");
// event sent from Tilesets.comboBoxChangeHandler()
tilesetsModel.setSelectedTileset(event.data as String);
}
Other events and commands work properly in the project, so I am wondering where I should start looking really... If anyone could help, it would be greatly appreciated!
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | 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
1 Posted by krasimir on 11 Nov, 2011 07:03 PM
Hello,
1. Basically you can add the "dispatch" method as a handler function of your events (in the mediator. I mean there is no need to have redispatchEventHandler type of functions, except if you want to debug something.
2. Check if the mapping of the event to the command is made after the dispatching of the event in the mediator.
Support Staff 2 Posted by Ondina D.F. on 11 Nov, 2011 07:10 PM
Hi Jansen,
“On the side of the SetSelectedTilesetCommand, it seems like it's never called at all...”
Does this mean that your Command has been executed?
Can you see the first trace in your SetSelectedTilesetCommand.execute() method?
If the answer is yes, then next question is:
Have you injected the event into your command?
You can't access the payload of your event if you didn't inject it into the command.
Let us know if it still doesn't work after injecting the event or if that wasn't the issue.
Ondina
3 Posted by jansensan on 11 Nov, 2011 07:23 PM
@ krasimir: I'll answer to your points in numbers, like you did ;) 1. Nice trick, I did not think of it this way, I'll do that in the future.
2. The mapping happens before I call my view.init(). See the output below:
@ Ondina D.F.: I mean that I never see the trace. Concerning the event, yes I inject it. Below is the full command:
Support Staff 4 Posted by Ondina D.F. on 11 Nov, 2011 07:24 PM
Adding another possibility:
In your MapEditorEvent class you need to override clone()
override public function clone():Event
{ return new MapEditorEvent (type, payload, bubbles, cancelable); } Did you do that?
5 Posted by jansensan on 11 Nov, 2011 07:28 PM
That's an interesting point! I recently created an AbstractDataEvent class in which I moved that there, let me test that!
Support Staff 6 Posted by Ondina D.F. on 11 Nov, 2011 07:32 PM
It should look like so:
public function SomeEvent(type:String, payload:String, bubbles:Boolean=false, cancelable:Boolean=false)
{
_payload=payload;
super(type, bubbles, cancelable);
}
override public function clone():Event
{
return new SomeEvent(type, payload, bubbles, cancelable);
}
private var _payload:String;
public function get payload():String
{
return _payload;
}
Support Staff 7 Posted by Ondina D.F. on 11 Nov, 2011 07:34 PM
"That's an interesting point! I recently created an AbstractDataEvent class in which I moved that there, let me test that!" o.k.
I have to go now. Krasimir will take it from here:)
8 Posted by jansensan on 11 Nov, 2011 07:35 PM
Brilliant! That was exactly the issue here! Thanks so much for thinking of that stuff!
9 Posted by krasimir on 11 Nov, 2011 07:56 PM
You are welcome ;)
Support Staff 10 Posted by Ondina D.F. on 13 Nov, 2011 08:39 AM
You’re welcome, indeed!
Ondina
[ Feel free to reopen this discussion in case you have more questions or you need further assistance with this issue. Please open new threads for new issues. ]
Ondina D.F. closed this discussion on 13 Nov, 2011 08:39 AM.