tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/62-injecting-a-uint-into-a-signal-commandRobotlegs: Discussion 2018-10-18T16:35:10Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-03-21T15:41:41Z2010-03-21T15:41:41ZInjecting a uint into a signal command<div><p>Hi Conrad,</p>
<p>What does the LoadCollection signal look like?</p>
<p>I'm assuming it does</p>
<p>super(uint) in the constructor?</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-03-21T16:37:30Z2010-03-21T16:37:31ZInjecting a uint into a signal command<div><p>I encountered the same problem just the other day and soon
realized that switching from int to Number solved the issue. Its
not the perfect solution but it works.</p>
<p>Cheers<br>
/ M</p></div>marteinntag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-03-21T18:13:06Z2010-03-21T19:01:36ZInjecting a uint into a signal command<div><p>Conrad and marteinn,</p>
<p>I'm not entirely sure, but I think that's caused by a bug in<br>
SwiftSuspenders that misinterprets ints and uints as numbers
when<br>
mapping values. This should be resolved in the current beta of<br>
SwiftSuspenders 1.5.<br>
If you want to try using that beta version (which is very stable
and<br>
should have production quality IMO), you can do so by downloading
it<br>
from the <a href=
"http://github.com/tschneidereit/SwiftSuspenders/downloads">SwiftSuspenders
downloads<br>
page</a> and<br>
putting the contained SWC file into your project's libs folder.</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-03-21T18:14:41Z2010-03-21T18:14:41ZInjecting a uint into a signal command<div><p>Hey Till, there is an issue with Vectors too along the same
lines...</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-03-21T18:16:27Z2010-03-21T18:16:30ZInjecting a uint into a signal command<div><p>Yep - the signal does have super(uint) in it, and switching to
Number does inded make it work - will have to look at the source
code of SwiftSuspenders as that is where the error occurs.</p></div>Conrad Winchestertag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-03-21T18:55:17Z2010-03-21T18:55:17ZInjecting a uint into a signal command<div><p>As I said, the SwiftSuspenders 1.5 shouldn't have that issue as
of<br>
beta 4 (I think). Jon Toland made me aware of the issue and
kindly<br>
provided a patch that resolved it, too.</p>
<p>Vectors are another issue, unfortunately. While I could add
an<br>
exception for them, too, that would make SwiftSuspenders
incompatible<br>
with Flash Player 9. Currently, I think there are still too
many<br>
projects that don't really require anything only Flash Player
10<br>
provides and should thus target 9.</p>
<p>An option would be to add preprocessing rules to the source code
and<br>
provide SWCs for FP 9 and 10. Patches for that are very welcome -
I<br>
won't be able to implement that myself for at least the next couple
of<br>
weeks.</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-03-21T19:14:55Z2010-03-21T19:14:55ZInjecting a uint into a signal command<div><p>On the Vector issue, I'm working around it by using a wrapper
class on the occasional Vector. I prefer not to inject the base
classes but one of my signal command mappings does need it.</p>
<p>I hadn't really sussed out why it wasn't working - just that it
wasn't, and the first work around I tried happened to work so I
stuck with it.</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-03-21T19:17:54Z2010-03-21T19:17:58ZInjecting a uint into a signal command<div><p>OK,</p>
<p>I built Robot Legs againt the 1.5 beta of Swift suspenders - A
lot of tests fail, but the resulting swf is usable (?) and when I
run my application I get the same error - probably something fishy
going on - am going with Number hack for the moment.</p>
<p>Conrad</p></div>Conrad Winchestertag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-04-30T01:11:32Z2010-04-30T01:11:37ZInjecting a uint into a signal command<div><p>The problem still exists in 1.5 beta. I'm trying to use a
DisplayObject as the payload in my signal and I get the same error.
If I change the type to String. Everything works fine and my
command gets instantiated and executed.<br></p></div>Danieltag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-04-30T10:33:55Z2010-04-30T10:33:55ZInjecting a uint into a signal command<div><p>That sounds like it's a different problem. Maybe you're
using<br>
DisplayObject as the type to be injected into your signal when
the<br>
actual mapped payload is a Sprite or MovieClip?</p>
<p>Unfortunately, it's not possible to efficiently implement
automated DI<br>
for injecting sub-types of the requested type (in this example,<br>
letting Sprite, Shape or MovieClip mappings satisfy a request
for<br>
DisplayObject), so you have to match your mappings to your
injection<br>
points exactly.</p>
<p>If none of the above fits your problem, maybe you could attach
a<br>
reduced test-case exposing your problem to the ticket?</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-04-30T16:55:23Z2010-04-30T16:55:24ZInjecting a uint into a signal command<div><p>I wasn't aware of the limitation with DI. Let me know if I
should open a ticket for the following scenario</p>
<p>I'm use the popup manager to display a popup from within a
command and want to send the parent displayobject via signal to
command. So where I dispatch the signal,</p>
<p>// where I dispatch I have mySignal.dispatch( myComponent as
DisplayObject);</p>
<p>// signal command [Inject] public var parent:DisplayObject;</p>
<p>As a workaround, I used the Application object to get the root
display object so no longer needed to pass in the parent display
object, but I thought this should still work.<br></p></div>Daniel tag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-05-02T16:14:01Z2010-05-02T16:14:01ZInjecting a uint into a signal command<div><p>To be honest, I'm not that well acquainted with the signals
extension,<br>
so I'm not too sure what's going on behind the scenes between
your<br>
"mySignal.dispatch" and the command creation.</p>
<p>Still: If I understand correctly, the SignalCommandMap creates
a<br>
temporary injector mapping for all payload items of the signal,
so<br>
that these items can be injected into the then created command,
right?</p>
<p>If so, there's no need to open a ticket: It's simply not
feasible to<br>
create temporary mappings for anything but the concrete type of
the<br>
payload. In cases where you're creating the injector mappings<br>
yourself, you can easily map a super type to a sub type value
(e.g.<br>
injector.mapValue(DisplayObject, new Sprite())), but in cases
where<br>
the system creates the mappings for you, as is the case in the<br>
SignalCommandMap, it can't know which type you want to have mapped,
so<br>
it has to use the concrete type. (See<br>
<a href=
"http://github.com/darscan/signals-extensions-CommandSignal/blob/master/src/org/robotlegs/base/SignalCommandMap.as#L93">
http://github.com/darscan/signals-extensions-CommandSignal/blob/mas...</a><br>
for how this works).</p>
<p>The only thing you can do in this case (apart from working
around the<br>
issue altogether as you did for now) is to change your
injection:<br>
[Inject] public var parent:Sprite;</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-06-05T16:28:10Z2010-06-05T16:28:10ZInjecting a uint into a signal command<div><p>Woah! I fixed the uint bug and know what is causing it and it
isn't very nice :-( This bug affected ints as well and is caused by
what I can only consider to be a bug in the flash player.</p>
<p>It turns out that if you have</p>
<p>var a:uint=0;</p>
<p>OR</p>
<p>var a:int=0;</p>
<p>then a.constructor is Number - this is absolutely wrong :-(</p>
<p>SignalCommandMap then fails and need the following change</p>
<pre>
<code> protected function getConstructorForObject(object:Object):Class
{
var constructor:Class;
if(object is Proxy || object is XML)
{
var name:String = getQualifiedClassName(object);
constructor = Class(getDefinitionByName(name));
}
else if (object is uint)
{
constructor = uint;
}
else if (object is int)
{
constructor = int;
}
else
{
constructor = object.constructor;
}
return constructor;
}</code>
</pre>
<p>Then all is well<br></p></div>Conrad Winchestertag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-06-05T18:21:01Z2010-06-05T18:21:02ZInjecting a uint into a signal command<div><p>Hmm, so this seems to be still valid:<br>
<a href=
"http://blog.andre-michelle.com/2007/weird_behavior_of_numbers_in_as3/">
http://blog.andre-michelle.com/2007/weird_behavior_of_numbers_in_as3/</a></p></div>Philipptag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-06-06T08:03:00Z2010-06-06T08:03:02ZInjecting a uint into a signal command<div><p>STOP!!! I was wrong, this does not fix the problem. It turns out
that the AVM2 treats Numbers, uints and ints in a very strange way
and you can never be sure you have what you want. So I have another
fix that does seem to work. You need to use the valueClasses array
from the Signal rather than getConstructorForObject in order to map
the injection. the code looks like this</p>
<p>protected function routeSignalToCommand(signal:ISignal,
valueObjects:Array, commandClass:Class, oneshot:Boolean):void<br>
{</p>
<pre>
<code> createCommandInstance(signal.valueClasses, valueObjects, commandClass).execute();
if ( oneshot )
unmapSignal( signal, commandClass );
}
protected function createCommandInstance(valueClasses:Array, valueObjects:Array, commandClass:Class):Object
{
var tempInjector:IInjector = injector.createChild();
for (var i:uint=0;i<valueClasses.length;i++)
{
tempInjector.mapValue(valueClasses[i], valueObjects[i]);
}
return tempInjector.instantiate(commandClass);
}</code>
</pre>
<p>This seems to work as you would expect.</p>
<p>I have offered this to Joel as a patch, along with some tests.
He might include it in the official release of SignalCommandMap</p></div>Conrad Winchestertag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-06-06T08:06:35Z2010-06-06T08:06:35ZInjecting a uint into a signal command<div><p>Looks good to me :></p>
<p>As long as the tests pass I love seeing code getting nuked.</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/12757942010-06-07T05:32:53Z2010-06-07T05:32:54ZInjecting a uint into a signal command<div><p>So, just to confirm, the current version of SignalCommandMap now
supports injection of ints and uints into commands.</p></div>Conrad Winchester