tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/44-trouble-understanding-event-injection-as-seen-in-robotlegsdemosflashgooglemapsRobotlegs: Discussion 2018-10-18T16:35:08Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/9043872010-01-24T23:13:06Z2010-01-24T23:13:08Ztrouble understanding event injection as seen in robotlegs.demos.flashgooglemaps<div><pre>
<code>public class GeoCodingCommand extends Command
{
[Inject]
public var service:GeoCodingService;
[Inject]
public var event:SystemEvent;
//--------------------------------------------------------------------------
//
// Overridden API
//
//--------------------------------------------------------------------------
override public function execute():void
{
service.requestGeocoding(event.body.city, event.body.address);
}
}</code>
</pre>
<p>I do not understand how the code from
'robotlegs.demos.flashgooglemaps' seen above avoids throwing this
Error:<br></p>
<pre>
<code> Injector is missing a rule to handle injection into target ...</code>
</pre>
<p>My similar code throws the above Error unless I include
something like:<br></p>
<pre>
<code> var event:SystemEvent = new SystemEvent(SystemEvent.CONSTANT);
injector.mapValue(SystemEvent, event);</code>
</pre></div>%tag:robotlegs.tenderapp.com,2009-10-18:Comment/9043872010-01-24T23:35:12Z2010-01-24T23:35:12Ztrouble understanding event injection as seen in robotlegs.demos.flashgooglemaps<div><p>The CommandMap sets up a temporary rule that maps the event (by
it's concrete class) for injection just before execute() is
called:</p>
<p><a href=
"http://github.com/robotlegs/robotlegs-framework/blob/master/src/org/robotlegs/base/CommandMap.as#L154">
http://github.com/robotlegs/robotlegs-framework/blob/master/src/org...</a></p>
<p>The injection must be exactly the same event class that triggers
the Command. So, if this triggers the command:</p>
<pre>
dispatch(new CrazyEvent(CrazyEvent.BOOM));
</pre>
<p>The injection in the command must be specified like this:</p>
<pre>
[Inject] public var event:CrazyEvent;
</pre>
<p>This will not work:</p>
<pre>
[Inject] public var event:Event;
</pre>
<p>Hope that helps. Let me know if you're still getting an
error.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/9043872010-01-25T10:02:31Z2010-01-25T10:04:23Ztrouble understanding event injection as seen in robotlegs.demos.flashgooglemaps<div><p>thanks much for your explanation.</p>
<p>my code now works, but I had to:<br>
<code>commandMap.mapEvent(ModelEvent.REQUEST_LOAD,
RequestLoadCommand, ModelEvent);</code><br>
via:<br>
<code>dispatchEvent(new
ContextEvent(ContextEvent.STARTUP));</code></p>
<p>previously I had this in my Context::startup:<br>
<code>commandMap.mapEvent(ModelEvent.REQUEST_LOAD,
RequestLoadCommand, ModelEvent);<br>
super.startup();</code></p>
<p>... somehow the mapping needs to be done in response to
ContextEvent.STARTUP rather than Context.startup</p></div>%