How can non Actor class listen to eventDispatching though the RobertLegs framework

Adam's Avatar


06 Dec, 2011 10:15 AM

How can non Actor class listen to roberleg eventDispatching and send events. I have a CustomNetLoader class that has to extends NetLoader, but at the same time I wan't it to send and receive event for Actor class's like Mediators. What is the best way to do this?

  1. 1 Posted by Michal Wroblews... on 06 Dec, 2011 10:48 AM

    Michal Wroblewski's Avatar

    Hi Adam,
    In > RobotLegs < it'd be better to have a class that has CustomNetLoader (not is). You're probably building a Service. So you should not be listening to any events. All other tiers (e.g. Commands) should use the service's interface to call methods on it. Then the service can call an method on your CustomNetLoader instance inside your service, listen to it's events and re-dispatch them to the framework.


  2. 2 Posted by adam on 06 Dec, 2011 11:06 AM

    adam's Avatar

    Thanks for the quick request. But here it's really not possible. The project is a player using OSMF. I have to make custom class deep into OSMF and all the way though OSMF reaching the CustomNetLoader - so wrappin it with at Service is not possible. I still think that eventDispatching between Actor and non Actor shout be possible.

  3. 3 Posted by Michal Wroblews... on 06 Dec, 2011 11:52 AM

    Michal Wroblewski's Avatar

    Ok, so you can do something like this. Add code above to the CustomNetLoader:

    public function get eventDispatcher():IEventDispatcher
        return _eventDispatcher;
     * @private
    public function set eventDispatcher(value:IEventDispatcher):void
        _eventDispatcher = value;
        _eventDispatcher && onEventDispatcher()
    public function onEventDispatcher():void
        //add some listeners here

    Then find an instance of IInjector and instance of CustomNetLoader. then do injector.injectInto(customNetLoader). It will fill customNetLoader with an instance of shared eventDispatcher. You can also inject any other mapped class.

    But remember it's not considered as a best practice :)


  4. 4 Posted by Adam on 06 Dec, 2011 12:33 PM

    Adam's Avatar

    Thanks, I just make a small test, here it work fine and I'm aware of this not been the best practice.

  5. 5 Posted by Adam on 06 Dec, 2011 12:59 PM

    Adam's Avatar

    Hi Mike

    Follow up question. As mention before the is a serie of custom OSMF class that in the end uses CustomNetLoader, so there no class in the neighborhood (Law of Demeter) , so how shout I get the IInjector in the class the instance the CustomNetLoaded class?


  6. 6 Posted by Michal Wroblews... on 06 Dec, 2011 01:11 PM

    Michal Wroblewski's Avatar

    I don't know, you have 2 options. Singleton or have an access from outside.
    Try to get an access to the instance of CustomNetLoader, from Mediator or something else.
    If it's not possible then create a class like InjectorForCustomNetLoader with static injector:IInjector reference. Provide injector object there and access it from CustomNetLoader.

    It's so dirty...

  7. Support Staff 7 Posted by Ondina D.F. on 06 Dec, 2011 01:35 PM

    Ondina D.F.'s Avatar

    Hi Adam and Mike,

    Have you guys seen this:

    I didn’t try it yet and also didn’t read the whole article, so I have no idea whether it is a good solution or not, but you might want to take a look at it.
    Mike could tell you if it’s a good approach or not.

  8. 8 Posted by Adam on 07 Dec, 2011 10:41 AM

    Adam's Avatar

    Hi Ondina,

    Thanks for pointing out the implementation of RobotLegs and OSMF, and interesting to see an implementation. No to sound superior in any way, but the problem as I see it is a bit deeper. Thanks for the tip.

  9. Support Staff 9 Posted by Ondina D.F. on 07 Dec, 2011 12:11 PM

    Ondina D.F.'s Avatar

    No problem. I didn’t want to interrupt your discussion. It was just a tip, as you’ve noticed.
    I’m sure Mike has more experience with an OSMF player than me and he already understood your use case, so he’ll assist you further :)

    Personally, I would use an interface to let a robotlegs application communicate with a non-robotlegs application. I’d probably load the player as a Module, and use an interface or a DynamicEvent for communication.
    Just my 2 cents.

  10. Ondina D.F. closed this discussion on 05 Jan, 2012 09:05 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