Problem with null dispatcher in a mediator
I'm having trouble getting running with my first serious Robotlegs app. I'm new to RL but with 10 years AS/Flex/Flash experience so am probably making a obvious mistake, like not instantiating something. I've got one Context, in which I'm attempting to map a Mediator to a view component. In the FLA there are is a component on stage which is linked to a component class. In the Context, I'm doing this to map to that component:
var ClassReference:Class = getDefinitionByName("MyClassName") as Class;
mediatorMap.mapView(ClassReference, MyMediator);
this works ok as the ClassReference is set correctly. I have also tried mapping to a given class name which works ok as well.
However, when I run it dies in my Mediator's onRegister function. I'm calling addContextListener to create an event listener, but it eventually dies in EventMap.mapListener.. the dispatcher parameter passed through from Mediator.addContextListener is null.
I'm at a loss to understand why it is null. Please help!
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 Stray on 21 Sep, 2010 12:08 PM
Have you traced out your view property in the onRegister()?
Is that null / not null?
Let me know and I'll help you chase this.
Support Staff 2 Posted by Shaun Smith on 21 Sep, 2010 12:13 PM
Sounds like metadata is being stripped out.
How are you compiling your app? If you're using the Flash IDE you need to select Export SWC (under Publish Setting). If you're using Flash/Flex builder (or another IDE that uses the MXMLC compiler) and you're compiling against the RL source, you need to add the following to your compiler options:
-keep-as3-metadata+=Inject -keep-as3-metadata+=PostConstruct
(note: the RL SWC includes these compiler options for you, so you only need to add them if you're compiling against the source).
Let me know if that helps.
3 Posted by grimep on 21 Sep, 2010 01:36 PM
Hi Shaun, thanks very much for the reply. At the moment I'm coding/using the debugger in Flex Builder but doing a ctrl-enter in Flash to compile, until I get round to sorting an Ant script for an MXMLC build, but I'll add the options for future reference. I had this problem while using the swc, so switched to using the Rl source so I could trace.
ok, so I've checked Export swc in Flash publish settings, its now dying with this:
Error: Injector is missing a rule to handle injection into target [object AdvStatsSubNavMediator]. Target dependency: com.g2.core.view.components::TabNavigator
Looking through here this seems to be a common issue. However, having read a couple of the issues I'm not sure how to apply a fix to my case....
Support Staff 4 Posted by Shaun Smith on 21 Sep, 2010 03:41 PM
That error is saying that the Injector doesn't know how to provide
AdvStatsSubNavMediator
with aTabNavigator
. How have you mappedTabNavigator
?5 Posted by grimep on 21 Sep, 2010 04:31 PM
Right, I stupidly had an [Inject]public var view:TabNavigator; in my mediator, so removing that allows it all to run without an exception, however I'm not yet doing anything useful.
I need my mediator to refer to the view class so it can mediate it (ie inject it manually). I've been advised that I need to do this in postConstruct, however my postConstruct() in the mediator isn't running...
[PostConstruct] private function postConstruct():void
{
}
Is there something I need to do to cause postConstruct to run? (Note, I'm referring to the view class using getDefinitionByName as I have several components based on the same TabNavigator class, each needing a different mediator, though this shouldn't matter AFAIK). Apols for the newbiness...
6 Posted by Stray on 21 Sep, 2010 04:39 PM
Injection / PostConstruct properties and methods should always be public. Yours is private :)
Support Staff 7 Posted by Shaun Smith on 21 Sep, 2010 07:18 PM
"I need my mediator to refer to the view class so it can mediate it (ie inject it manually)."
I don't think you'd need to inject it manually - the framework is designed to inject view components into mediators automatically. The general pattern is this:
And then in MediatorClass:
The view's type must match the mapping exactly (in this case ViewClass). It will be injected before onRegister() is called.
If you need to inject the view as a different type, you can use the third parameter of mapView:
And then in MediatorClass:
Methods marked with [PostConstruct] are called by the Injector after all dependencies have been injected, but in the case of a mediator, onRegister() already provides us with that hook.
Hope that helps! Let me know if I'm misunderstanding what you're wanting to do.
8 Posted by grimep on 22 Sep, 2010 01:41 PM
Guys, thanks again for the time and help. What was bothering me was the fact that the view class is auto-generated by Flash compiler, and not in my source tree, so I assumed that doing:
[Inject]public var view:AutoGenViewClass; would fail to compile- I thought I'd need to get a handle on the class instance with getDefinitionByName, and wasn't sure how I'd manage that with injection defined by a meta tag, hence thinking I'd need to manually inject. But, it seems to be ok now.
Stray closed this discussion on 10 Feb, 2011 05:50 PM.