eventMap problem in actor
Hello,
I have a problem with an eventMap wich doesn't listen my event.
Maybe I use wrong it :
I have a loader:Loader and I try to listen Complete Event from his
contentLoaderInfo in a Service wich extends Actor :
public class LoadModuleService extends Actor implements
ILoadModuleService
eventMap.mapListener(_loader.contentLoaderInfo,
Event.COMPLETE, _moduleLoaded);
in my context :
injector.mapClass(ILoadModuleService,
LoadModuleService);
The method "_moduleLoaded" is never called.
If I write :
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
_moduleLoaded);
It works !
We can use eventMap on no RL elements or we need use default addEventListener way ?
For information, I call this service via a Command just after the startup Complete. If I call it later, it works...
I attach simplified sources.
Thanks !
- simple.rar 1.95 KB
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
Support Staff 1 Posted by Joel Hooks on 26 Feb, 2010 02:10 AM
Hi,
I've tested this and can't reproduce the problem. I've attached a simple test application (that is rather silly, but does perform the actions).
Support Staff 2 Posted by Joel Hooks on 26 Feb, 2010 02:59 AM
I was looking in your context:
injector.mapClass(ILoadModuleService, LoadModuleService);
This will load a new instance of the service with every call, is that intentional? I'd almost guess that you are getting garbage collected. The reason it gets GC'd is that there is no reference to the Actor anywhere. It is create the one time in the command and then gets GC'd. eventMap uses a weak reference, addEventListener is a GC blocking ref. If you use mapSingletonOf the Injector keeps a ref. Because you are using mapClass no ref is kept anywhere and you get fail.
Joel Hooks closed this discussion on 26 Feb, 2010 02:59 AM.
myrddin re-opened this discussion on 26 Feb, 2010 08:50 AM
3 Posted by myrddin on 26 Feb, 2010 08:50 AM
First, thank you for your answer.
Yes, it is intentional. I understand what you're explaining to me.
After the command executed, my command and my service are GC'd, even if my service has not terminated his action.
Either I execute my loading in the command, or I map my service as a singleton ? What is the better way ?
Support Staff 4 Posted by Joel Hooks on 26 Feb, 2010 08:56 AM
Or, option 3, don't use the eventMap and stick with addEventListener. If you need a unique instance of the service for every injection and have to use mapClass, then do that. Otherwise use injector.mapSingletonOf().
Joel Hooks closed this discussion on 26 Feb, 2010 08:56 AM.