tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/229-commandmapexecute-and-injection-of-a-property-of-type-stringRobotlegs: Discussion 2018-10-18T16:35:20Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/41690242010-12-08T14:24:33Z2010-12-08T14:24:33ZcommandMap.execute() and injection of a property of type String<div><p>Your text / string injection isn't being fulfilled.</p>
<p>I'm guessing that you've got yourself confused about what gets
injected in the normal command map.</p>
<p>If this is the signal command map then the signal dispatch
parameters do get injected directly.</p>
<p>But for the normal command map, the event that triggered the
command, and not the properties of the event, is injected.</p>
<p>so</p>
<pre>
<code>[Inject]
public var alertEvent:AlertEvent;</code>
</pre>
<p>or whatever your event is.</p>
<p>and then...</p>
<pre>
<code>eiService.alert(alertEvent.text);</code>
</pre>
<p>Hope that fixes it for you!</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/41690242010-12-08T14:32:02Z2010-12-08T14:32:02ZcommandMap.execute() and injection of a property of type String<div><p>you know what, this command is not mapped at all, but getting
called though. strange!<br>
in addition if i add this mapping in the context</p>
<pre>
<code>injector.mapSingleton(String);</code>
</pre>
<p>the dependency is fulfilled.</p>
<p>but now even stranger, the command is constructed in a endless
loop every few hundred miliseconds...</p></div>tomtag:robotlegs.tenderapp.com,2009-10-18:Comment/41690242010-12-08T14:45:10Z2010-12-08T14:45:10ZcommandMap.execute() and injection of a property of type String<div><p>Hi Tom - mapping a Singleton for a base class is bound to make
things go a bit crazy :)</p>
<p>You could equally do</p>
<pre>
<code>injector.mapValue(String, "Hello world")</code>
</pre>
<p>and the injection would be fulfilled with "Hello world" but my
assumption is that your alert message is somehow related to the
event that triggers the alert?</p>
<p>The command cannot run unless either it is being mapped or you
are calling it manually.</p>
<p>If you have more than one event with the same string type, and
you haven't mapped your command against the event class too, then
you could see false firings.</p>
<p>If you want to paste your actual mappings in I'll be happy to
take a closer look.</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/41690242010-12-08T14:52:43Z2010-12-08T14:52:43ZcommandMap.execute() and injection of a property of type String<div><p>yes - i need to display a javascript alert popup (using
ExternalInterface). i do have a service that wraps around
ExternalInterface so my modules can utilize it by passing events on
the module bus.<br>
i guess i should use an event and simply map the command
accordingly.<br>
but i dislike the fact that i should have to write more code, so i
tried to use commandMap.execute().</p></div>tomtag:robotlegs.tenderapp.com,2009-10-18:Comment/41690242010-12-08T14:59:16Z2010-12-08T14:59:16ZcommandMap.execute() and injection of a property of type String<div><p>More/less code should not really be the basis of your design
decisions - there are many, many things to consider that come
further up the list than "typing".</p>
<p>I imagine chasing down this bug has been a lot more time and
energy consuming than doing it the "more code" way? I think it
takes me about 3 minutes to create a custom Event... ;)</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/41690242010-12-08T15:00:30Z2010-12-08T15:00:30ZcommandMap.execute() and injection of a property of type String<div><p>ok, lesson learnt. thanks a lot for your support!</p></div>tomtag:robotlegs.tenderapp.com,2009-10-18:Comment/41690242010-12-08T21:46:33Z2010-12-08T21:46:33ZcommandMap.execute() and injection of a property of type String<div><p>Hi Tom,</p>
<p>You should be able to do this:</p>
<pre>
public final class JsAlertCommand extends ModuleCommand
{
[Inject(name="MyText")]
public var text : String;
[Inject]
public var eiService : IExternalInterfaceService;
override public function execute() : void {
eiService.alert(text);
}
}
</pre>
<p>And then:</p>
<pre>
commandMap.execute(JsAlertCommand, 'foobaz!', String, 'MyText');
</pre>
<p>The command does not need to be mapped for this to work. When
injecting primitives (String, Number, int etc) it's best to use
named injection. Hope that helps!</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/41690242010-12-17T17:31:07Z2010-12-17T17:31:07ZcommandMap.execute() and injection of a property of type String<div><p>this is working like a charm. thanks a lot!</p></div>tom