Dispatching an event via the context

philostler's Avatar

philostler

25 Feb, 2013 04:45 PM

In RL1 I was able to dispatch an event via the context and have it to be picked up and handled accordingly. E.g.

(context as IEventDispatcher).dispatchEvent(new ApplicationEvent(ApplicationEvent.WIRING_COMPLETE));

In RL2 this no longer works. What is the correct "way" to now dispatch to Robotlegs when you only have a handle on the Context?

Thanks

  1. Support Staff 1 Posted by Ondina D.F. on 25 Feb, 2013 05:05 PM

    Ondina D.F.'s Avatar

    Hi philostler,

    Inside of Mediators you have access to the shared event dispatcher, and you can use it like this:

    dispatch(new SomeEvent(SomeEvent.SOMETHING_HAPPENED));

    For any other class that needs the dispatcher you’d have to inject it or let the injector instantiate it:
    [Inject] public var eventDispatcher:IEventDispatcher;

    or if you need it in your config class, you can do this:
    eventDispatcher=injector.getInstance(IEventDispatcher);

    eventDispatcher.dispatchEvent(new SomeEvent(SomeEvent.SOMETHING_HAPPENED));

    For this to happen you need to install the EventDispatcherExtension, or to install the MVCSBundle which includes the EventDispatcherExtension as well.
    [https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...]

    Ondina

  2. 2 Posted by philostler on 25 Feb, 2013 05:12 PM

    philostler's Avatar

    I've adapted one of your suggestions to work with what I've got...

    context.injector.getInstance(IEventDispatcher);

    Works great. Thanks!

  3. Support Staff 3 Posted by Ondina D.F. on 25 Feb, 2013 05:18 PM

    Ondina D.F.'s Avatar

    No problem:)

  4. Ondina D.F. closed this discussion on 26 Feb, 2013 09:38 AM.

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