tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/169-passing-a-reference-using-signals-and-commandsRobotlegs: Discussion 2018-10-18T16:35:17Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/28416702010-09-06T10:58:35Z2010-09-06T10:58:35ZPassing a reference using Signals and Commands <div><p>I'm not familiar with signals but from what I've seen the boot strapping is similar. I'm probably no help but could you post your context so I can see if you've got everything mapped?</p>
<p>Cheers,</p>
<p>Scott</p></div>darloScottttag:robotlegs.tenderapp.com,2009-10-18:Comment/28416702010-09-06T11:04:38Z2010-09-06T11:04:38ZPassing a reference using Signals and Commands <div><p>Thanks apprentice it,</p>
<p>/**</p>
<pre><code> * Constructor
*/
public class ArAppContext extends SignalContext
{
public function ArAppContext(contextView:DisplayObjectContainer=null, autoStartup:Boolean=true)
{
super(contextView, autoStartup);
}
/**
* override function
*/
override public function startup():void
{
injector.mapSingleton(FlarMangerAddedSignal);
injector.mapSingleton(Create3DSceneSignal);
// Map some Commands to Events
commandMap.mapEvent(ContextEvent.STARTUP_COMPLETE, FlarMangerCommand, ContextEvent, true);
signalCommandMap.mapSignalClass(FlarMangerAddedSignal, FlarMangerAddedCommand);
signalCommandMap.mapSignalClass(Create3DSceneSignal, Create3DSceneCommand);
// Here we bind Mediator Classes to View Classes.
// Mediators will be created automatically when view instances arrive on stage
mediatorMap.mapView(FlarMangerView, FlarMangerMediator);
mediatorMap.mapView(Scene3DView, Scene3DMediator);
super.startup();
}
}</code></pre></div>Almogtag:robotlegs.tenderapp.com,2009-10-18:Comment/28416702010-09-06T11:20:06Z2010-09-06T11:20:06ZPassing a reference using Signals and Commands <div><p>Your use of Signals looks a bit off.</p>
<p>Rather than pass an instance, you should be passing a Class (type). Except that where you're subclassing the Signal (As you are) you don't need any params in the constructor at all - you fix them in the super() call in the constructor, as they won't vary.</p>
<p>So:</p>
<p>public class FlarMangerAddedSignal extends Signal<br />
</p>
<pre><code>{
public function FlarMangerAddedSignal()
{
super(Object);
}
}</code></pre>
<p>You only pass the instance at the time of dispatch.</p>
<p>However, there's not really much point having Object as your class type ... are you sure that you don't want to strongly type that? You'll loose the benefits of type checking and being able to rely on a strongly typed value in the handler for the dispatch.</p>
<p>Maybe you need to go back to Robert Penner's examples again? My feeling is that you've misunderstood how signals work, because you should also be passing an instance in your dispatch.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/28416702010-09-06T11:34:09Z2010-09-06T11:34:09ZPassing a reference using Signals and Commands <div><p>Hi Stray,<br />
I will take a look at it again but I think I do have it right,</p>
<p>flarMangerAddedSignal.dispatch(myFlarManger);</p>
<p>my dispatch, from my mediator flarMangerAddedSignal is my custom signal and myFlarManger is FlarManger which was created in my flarMangerView</p>
<p>flarManager = new FLARManager("Assets/XML/flarConfig.xml", new FLARToolkitManager(), this.stage);</p></div>Almogtag:robotlegs.tenderapp.com,2009-10-18:Comment/28416702010-09-06T12:20:34Z2010-09-06T12:20:34ZPassing a reference using Signals and Commands <div><p>Hi,</p>
<p>the reason I said I thought you were a little confused about signals is that your error was:</p>
<p>Error: Injector is missing a rule to handle injection into target [class FlarMangerAddedSignal]. Target dependency: Object, method: constructor, parameter: 1</p>
<p>The reason for this error is that, to fulfill the dependency you put in the constructor of the FlarManagerAddedSignal, you'd need to have mapped a value to Object. Mapping a value to Object wouldn't be advisable. You've also misunderstood the constructor params for Signal. You should be passing types (class names) not instances.</p>
<p>So - even if you've got your dispatch correct (the example you gave previously was a bit confusing as the dispatch was for your custom3D signal), it seems from the code below that your signal constructor should be more like:</p>
<p>public function flarManagerAddedSignal():void<br />
{</p>
<pre><code>super(FLARManager);</code></pre>
<p>}</p>
<p>this will stop the missing-dependency error you're hitting. It will also set your signal up to expect an instance of the FLARManager, rather than just a vanilla object.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/28416702010-09-06T15:43:54Z2010-09-06T16:12:35ZPassing a reference using Signals and Commands <div><p>Hi Almog,</p>
<p>As Stray pointed out, your dispatch looks fine, it's the way you are extending your Signal that is incorrect. The constructor for a custom Signal should look something like this:</p>
<pre>
public function FlarManagerAddedSignal():void
{
super(FLARManager);
}
</pre>
<p>Notice: no constructor arguments, and a <strong>class</strong> is being passed to super. This enables runtime type-checking (ensures that only instances of FLARManager can be dispatched from such a Signal).</p>
<p>You had this:</p>
<pre>
public function FlarMangerAddedSignal(myFlarMangerObject:Object)
{
super(myFlarMangerObject);
}
</pre>
<p>Notice: non-optional constructor argument, and an <strong>instance</strong> is being passed to super. One problem with this is that you won't get the runtime type-checking - it's simply not how you are supposed to create a custom Signal.</p>
<p>A bigger problem is that Robotlegs can't create an instance of this Signal for you because it has a non-optional constructor argument (myFlarMangerObject:Object). When Robotlegs tries to inject the Signal for the first time it attempts to construct it, sees the non-optional constructor argument, and throws an error because it has no idea how to provide the constructor argument needed to create an instance of this Signal.</p>
<p>My advice (and this applies to learning anything) would be to learn one new technology at a time. Trying to learn Robotlegs <strong>and</strong> Signals at the same time is just not pragmatic - when things go wrong you won't have the experience to know which technology is giving you problems.</p>
<p>The same is true when refactoring (or "cleaning up") code - if you change ten things in one go, and your program explodes, you won't know exactly which change caused the explosion. Smaller steps are better, just like learning.</p>
<p>Anyhow, let us know how you get on - changing your custom Signal should sort out the problem and put you back on track.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/28416702010-09-07T05:45:36Z2010-09-07T05:45:36ZPassing a reference using Signals and Commands <div><p>Thanks everyone,<br />
I do agree that it would be better to take it step by step however I thought my experiences with PureMVC would make it easier.</p>
<p>I went ahead a looked at all the documents and examples for signal and believe I understand it stand now it's fairly simple and removes a lot of boiler head code with customs events.</p>
<p>I followed your instructions which was great, it did solve my errors how every at some point my reference to FLARManger gos null.</p>
<p>I believe one of the main issues is using FlarManger and RobotLegs as FlarManger is coupled together with in its own framework.</p>
<p>I'm going to try to simplify everything just by passing a custom event with the view reference. Currently when I try to reach FlarMangerView from my Scen3DView it's null that might be the main issue. <br />
</p>
<p>Worst case I can go back to PureMVC :)</p>
<p>Thanks,<br />
Almog <br />
</p></div>Almogtag:robotlegs.tenderapp.com,2009-10-18:Comment/28416702010-09-07T06:42:17Z2010-09-07T06:42:17ZPassing a reference using Signals and Commands <div><p>Hi Everyone,<br />
Thanks for all your help I finally got it to work 100% I had a number of basic programming mistakes (working all nighters not a good thing). Once I went over everything it was just fine. On to the next step.</p>
<p>Almog</p></div>Almogtag:robotlegs.tenderapp.com,2009-10-18:Comment/28416702010-09-07T08:49:56Z2010-09-07T08:49:56ZPassing a reference using Signals and Commands <div><p>Awesome! Glad to hear that you are back on track :></p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/28416702010-09-07T10:36:16Z2010-09-07T10:36:16ZPassing a reference using Signals and Commands <div><p>Thanks</p></div>Almog