tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/311-and-one-more-null-eventdispatcher-inside-actor-derived-classRobotlegs: Discussion 2012-05-18T15:33:11Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/71393722011-05-10T15:12:41Z2011-05-12T15:40:02Zand one more null eventdispatcher inside Actor derived class<div><p>Hi,<br>
I wan't figure out what's happening here ... here's what's inside
my context:</p>
<pre>
<code>var m:EpodxModule = new EpodxModule();
injector.injectInto(m);
injector.mapValue( EpodxModule,m);</code>
</pre>
<p>then inside a model class:</p>
<pre>
<code>public class ModulesModel extends Actor
{
private var _m:EpodxModule;
[Inject]
public function set m(value:EpodxModule):void
{
_m = value;
}
public function get m():EpodxModule
{
return _m;
}
[...]
}</code>
</pre>
<p>Injection occurs as expected ... my m property is injected with
a brand new instance of EpodxModule Class.</p>
<p>BUT:</p>
<p>m property still has a null eventDispatcher that prevents it
from dispatching events for example !!! I checked by tracing it
inside [PostConstruct] init function and inside others ...</p>
<p>There must be something wrong inside my code but honestly I
can't see ...</p></div>peter.banniertag:robotlegs.tenderapp.com,2009-10-18:Comment/71393722011-05-10T15:54:42Z2011-05-10T15:54:42Zand one more null eventdispatcher inside Actor derived class<div><p>Hi there,<br>
could you post the code inside EpodxModule?</p>
<p>Does it definitely extend Actor?</p>
<p>I'm sure we can help you figure it out.</p>
<p>You're definitely not trying to access that eventDispatcher in
the constructor? (I know you said it's in a PostConstruct function
but it's worth checking).</p>
<p>BTW - m is a terrible name for a variable!</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/71393722011-05-11T07:38:59Z2011-05-12T15:40:02Zand one more null eventdispatcher inside Actor derived class<div><p>Hi!<br>
Sure m isn't a good choice !! :)<br>
After a few hours trying to find out what's wrong, I was a bit
uninspired for my variables names ...<br>
Anyway this is the EpodxModule Class:</p>
<p>public class EpodxModule extends Actor</p>
<pre>
<code>{
public var moduleName:String;
public var moduleURL:String;
public var view:Group;
public var moduleInfo:IModuleInfo;
public var module:IVisualElement;
public var licenseObject:Object;
public function EpodxModule()
{
super();
/*moduleName = _name;
moduleURL = _url;*/
}
[PostConstruct]
public function init():void
{
trace('PostConstruct '+_eventDispatcher);
}
override public function set eventDispatcher(value:IEventDispatcher):void
{
_eventDispatcher = value;
Alert.show("SET EVENT DISPATCHER");
}
override public function get eventDispatcher():IEventDispatcher
{
return _eventDispatcher;
}</code>
</pre>
<p>}</p>
<p>that's a pretty simple case isn't it ? I still can't see what's
wrong ...<br>
Thanks</p></div>peter.banniertag:robotlegs.tenderapp.com,2009-10-18:Comment/71393722011-05-11T08:09:04Z2011-05-11T08:09:04Zand one more null eventdispatcher inside Actor derived class<div><p>Hi Peter,</p>
<p>when you overrode the <code>set eventDispatcher</code> you lost
the <code>[Inject]</code> tag that was in the original
<code>Actor</code> class.</p>
<p>It should be:</p>
<pre>
<code>[Inject]
override public function set eventDispatcher(value:IEventDispatcher):void
{
_eventDispatcher = value;
Alert.show("SET EVENT DISPATCHER");
}</code>
</pre>
<p>Ref: Line 67 of<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/org/robotlegs/mvcs/Actor.as">
https://github.com/robotlegs/robotlegs-framework/blob/master/src/or...</a></p>
<p>If you reinstate that then you'll probably find things work as
they should - do let us know! If not then I'll help you do some
deeper digging, but injection is really pretty simple:</p>
<p>injection point + injection rule => process through injector
= happy code.</p>
<p>So there's a surprisingly small number of things that can go
wrong.</p>
<p>Hopefully this fixes it!</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/71393722011-05-11T08:10:54Z2011-05-11T08:10:54Zand one more null eventdispatcher inside Actor derived class<div><p>A completely different note - is there a reason why you're using
<code>mapValue</code> and instantiating the instance for yourself,
rather than using <code>mapSingleton</code> ?</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/71393722011-05-11T08:51:54Z2011-05-12T15:40:02Zand one more null eventdispatcher inside Actor derived class<div><p>Hi,<br>
thanks for the quick reply !<br>
That was it ! now I understand pretty well what was my mistake
...<br>
Now I can go happy coding ... big thanks!</p>
<p>I was using mapValue instead of mapSingleton as I want to have
the opportunity to have multiples instances if I want to ... that's
the right way isn't it ?</p>
<p>I had a relative conceptual question :</p>
<p>If I want a Class to act as a manager just like my ModulesModel
Class which is meant to handle multiples modules. This Class have a
few modules as properties. Here, with injection, I have to
instantiate those modules first inside my Context and then map
them. Would it be conceptualy better to handle their instantiation
inside the ModulesModel himself ?</p></div>peter.banniertag:robotlegs.tenderapp.com,2009-10-18:Comment/71393722011-05-11T08:56:01Z2011-05-11T08:56:01Zand one more null eventdispatcher inside Actor derived class<div><p>Hi Peter,</p>
<p>I'm glad I asked then because the answer is that
<code>mapClass</code> won't give you multiple instances (except
over time, you can switch out instances).</p>
<p>Essentially mapClass is identical to<code>mapSingletonOf(
)</code> except that you're controlling the creation of the
concrete instance.</p>
<p>Can I just clarify - when you talk about 'Modules' - do you mean
like Robotlegs Modules (using the modular utils) - or just Flex
Modules, or perhaps something totally different?</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/71393722011-05-11T09:03:34Z2011-05-12T15:40:02Zand one more null eventdispatcher inside Actor derived class<div><p>Hi,</p>
<p>I was talking about something different ... it could have been
anything ... just an example to picture the problem ...</p>
<p>thanks for your explanations and your support!</p></div>peter.banniertag:robotlegs.tenderapp.com,2009-10-18:Comment/71393722011-05-11T09:08:10Z2011-05-11T09:08:10Zand one more null eventdispatcher inside Actor derived class<div><p>Ah - ok - no problem. Basically if you want to have multiple
instances within a single context your best option is always to
create a container for them.</p>
<p>I'll close this now - shout again if you need any more help,</p>
<p>Stray</p></div>Stray