tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/739-how-can-non-actor-class-listen-to-eventdispatching-though-the-robertlegs-frameworkRobotlegs: Discussion 2012-01-05T09:05:06Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/119163272011-12-06T10:15:28Z2011-12-06T10:15:29ZHow can non Actor class listen to eventDispatching though the RobertLegs framework<div><p>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?</p></div>Adamtag:robotlegs.tenderapp.com,2009-10-18:Comment/119163272011-12-06T10:48:01Z2011-12-06T10:48:01ZHow can non Actor class listen to eventDispatching though the RobertLegs framework<div><p>Hi Adam,<br>
In > RobotLegs < it'd be better to have a class that
<em>has</em> CustomNetLoader (not <em>is</em>). 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.</p>
<p>Mike</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/119163272011-12-06T11:06:46Z2011-12-06T11:06:47ZHow can non Actor class listen to eventDispatching though the RobertLegs framework<div><p>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.</p></div>adamtag:robotlegs.tenderapp.com,2009-10-18:Comment/119163272011-12-06T11:52:20Z2011-12-06T11:52:20ZHow can non Actor class listen to eventDispatching though the RobertLegs framework<div><p>Ok, so you can do something like this. Add code above to the
CustomNetLoader:</p>
<pre>
<code>public function get eventDispatcher():IEventDispatcher
{
return _eventDispatcher;
}
[Inject]
/**
* @private
*/
public function set eventDispatcher(value:IEventDispatcher):void
{
_eventDispatcher = value;
_eventDispatcher && onEventDispatcher()
}
public function onEventDispatcher():void
{
//add some listeners here
}</code>
</pre>
<p>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.</p>
<p>But remember it's not considered as a best practice :)</p>
<p>Mike</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/119163272011-12-06T12:33:58Z2011-12-06T12:33:59ZHow can non Actor class listen to eventDispatching though the RobertLegs framework<div><p>Thanks, I just make a small test, here it work fine and I'm
aware of this not been the best practice.</p></div>Adamtag:robotlegs.tenderapp.com,2009-10-18:Comment/119163272011-12-06T12:59:38Z2011-12-06T12:59:38ZHow can non Actor class listen to eventDispatching though the RobertLegs framework<div><p>Hi Mike</p>
<p>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?</p>
<p>Adam</p></div>Adamtag:robotlegs.tenderapp.com,2009-10-18:Comment/119163272011-12-06T13:11:34Z2011-12-06T13:11:34ZHow can non Actor class listen to eventDispatching though the RobertLegs framework<div><p>I don't know, you have 2 options. Singleton or have an access
from outside.<br>
Try to get an access to the instance of CustomNetLoader, from
Mediator or something else.<br>
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.</p>
<p>It's so dirty...</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/119163272011-12-06T13:35:43Z2011-12-06T13:35:43ZHow can non Actor class listen to eventDispatching though the RobertLegs framework<div><p>Hi Adam and Mike,</p>
<p>Have you guys seen this:<br>
<a href=
"http://www.randytroppmann.com/2010/01/17/this-osmf-has-robotlegs/">
http://www.randytroppmann.com/2010/01/17/this-osmf-has-robotlegs/</a></p>
<p>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.<br>
Mike could tell you if it’s a good approach or not.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/119163272011-12-07T10:41:19Z2011-12-07T10:41:19ZHow can non Actor class listen to eventDispatching though the RobertLegs framework<div><p>Hi Ondina,</p>
<p>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.</p></div>Adamtag:robotlegs.tenderapp.com,2009-10-18:Comment/119163272011-12-07T12:11:44Z2011-12-07T12:11:44ZHow can non Actor class listen to eventDispatching though the RobertLegs framework<div><p>No problem. I didn’t want to interrupt your discussion. It
was just a tip, as you’ve noticed.<br>
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 :)</p>
<p>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.<br>
Just my 2 cents.</p></div>Ondina D.F.