Passing a reference using Signals and Commands
Hi,
I trying to pass a reference of FlarManger from my view class to another view my 3D Scene view. I keep getting errors. I new to RobotLegs so I'm thinking I either missing something or I'm doing something wrong I looked on support and on line docs couldn't find anything could really use the help on this.
Here is the code -
My mediator dispatches a signal
flarMangerAddedSignal.dispatch(myFlarManger);
FlarMangerAddedSignal looks like this
public class FlarMangerAddedSignal extends Signal
{
public function FlarMangerAddedSignal(myFlarMangerObject:Object)
{
super(myFlarMangerObject);
}
}
My command looks like this
/**
* On execute dispatch Create3DSceneSignal
*
*/
override public function execute():void
{
trace("FlarManger Added Command execute");
create3DScene.dispatch();
}
This is the error that I'm getting -
Error: Injector is missing a rule to handle injection into target [class FlarMangerAddedSignal]. Target dependency: Object, method: constructor, parameter: 1
I'm not sure were I need to add this, and when I try to add this to my context I getting another error.
Thanks
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by darloScottt on 06 Sep, 2010 10:58 AM
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?
Cheers,
Scott
2 Posted by Almog on 06 Sep, 2010 11:04 AM
Thanks apprentice it,
/**
3 Posted by Stray on 06 Sep, 2010 11:20 AM
Your use of Signals looks a bit off.
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.
So:
public class FlarMangerAddedSignal extends Signal
{
public function FlarMangerAddedSignal()
{
super(Object);
}
}
You only pass the instance at the time of dispatch.
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.
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.
Stray
4 Posted by Almog on 06 Sep, 2010 11:34 AM
Hi Stray,
I will take a look at it again but I think I do have it right,
flarMangerAddedSignal.dispatch(myFlarManger);
my dispatch, from my mediator flarMangerAddedSignal is my custom signal and myFlarManger is FlarManger which was created in my flarMangerView
flarManager = new FLARManager("Assets/XML/flarConfig.xml", new FLARToolkitManager(), this.stage);
5 Posted by Stray on 06 Sep, 2010 12:20 PM
Hi,
the reason I said I thought you were a little confused about signals is that your error was:
Error: Injector is missing a rule to handle injection into target [class FlarMangerAddedSignal]. Target dependency: Object, method: constructor, parameter: 1
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.
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:
public function flarManagerAddedSignal():void
{
super(FLARManager);
}
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.
Stray
Support Staff 6 Posted by Shaun Smith on 06 Sep, 2010 03:43 PM
Hi Almog,
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:
Notice: no constructor arguments, and a class is being passed to super. This enables runtime type-checking (ensures that only instances of FLARManager can be dispatched from such a Signal).
You had this:
Notice: non-optional constructor argument, and an instance 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.
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.
My advice (and this applies to learning anything) would be to learn one new technology at a time. Trying to learn Robotlegs and 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.
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.
Anyhow, let us know how you get on - changing your custom Signal should sort out the problem and put you back on track.
7 Posted by Almog on 07 Sep, 2010 05:45 AM
Thanks everyone,
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.
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.
I followed your instructions which was great, it did solve my errors how every at some point my reference to FLARManger gos null.
I believe one of the main issues is using FlarManger and RobotLegs as FlarManger is coupled together with in its own framework.
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.
Worst case I can go back to PureMVC :)
Thanks,
Almog
8 Posted by Almog on 07 Sep, 2010 06:42 AM
Hi Everyone,
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.
Almog
Support Staff 9 Posted by Shaun Smith on 07 Sep, 2010 08:49 AM
Awesome! Glad to hear that you are back on track :>
10 Posted by Almog on 07 Sep, 2010 10:36 AM
Thanks
Stray closed this discussion on 10 Feb, 2011 05:46 PM.