Can't get event dispatched from Command to run handler in Mediator
Trying to get a command to dispatch an event and have the application mediator catch it and do something. but it doesn't seem to work. I'm using the Macrobot extension. I've tried injecing an IEventDispatcher intot he command and dispatching an event there, and I've tried using the IContext to dispatch an event also.
Here is my context config:
```
public function configure():void
{
//other mappings
mediatorMap.map(PassportPOS).toMediator(AppMediator);
}
```
Here is the app's context view's mediator initialize function listening for the CONFIG_LOAD_FAILED event on the context
```
override public function initialize():void
{
super.initialize();
addContextListener(AppEvent.CONFIG_LOAD_FAILED, handleConfigLoadFail, AppEvent);
}
```
And here is the command that is dispatching the event:
```
public class LoadConfigService extends AsyncCommand implements ICommand
{
[Inject]
public var eventDispatcher:IEventDispatcher;
override public function execute():void
{
//non-relevant stuff
loadConfigFile();
}
private function loadConfigFile():void
{
var config:File = File.applicationDirectory.resolvePath("config.cf");
if (!config.exists)
{
//trying to dispatch from both context and eventDispatcher to see if either works
context.dispatchEvent(new AppEvent(AppEvent.CONFIG_LOAD_FAILED));
eventDispatcher.dispatchEvent(new AppEvent(AppEvent.CONFIG_LOAD_FAILED));
return;
}
//other stuff if config exists
}
}
```
The app mediator's handler is never being called when the AppEvent.CONFIG_LOAD_FAILED is sent out from the command
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 kamcknig on Aug 01, 2015 @ 04:32 PM
Nevermind. I was dispatching it in the wrong place in my code (code not shown in the question). It works as expected. Sorry!
kamcknig closed this discussion on Aug 01, 2015 @ 04:32 PM.