Model gets injected but it's properties and methods are undefined
Hi there,
This is my first robotlegs project and I have looked through several posts where people seemed to have a similar problem but still haven't found a solution.
In my Context, I am using mapSingletonOf() to map a Service injected into used by StartupCommand and Model injected into and used by PopulateModelCommand.
override public function startup ():void
{
commandMap.mapEvent(ContextEvent.STARTUP_COMPLETE, StartupCommand, ContextEvent);
commandMap.mapEvent(DataEvent.GALLERY_LOADED, PopulateModelCommand, DataEvent);
injector.mapSingletonOf(IBPModel, BPModel);
injector.mapSingletonOf(IDataService, XMLLocalService);
mediatorMap.mapView(Main, MainMediator);
mediatorMap.createMediator(contextView);
super.startup();
}
XMLLocalService gets injected and I can access it's method loadData() no problem at all. See below.
public class StartupCommand extends Command
{
[Inject]
public var service:IDataService;
override public function execute ():void
{
service.loadData();
}
}
However when I try and use BPModel
public class PopulateModelCommand extends Command
{
[Inject]
public var model:IBPModel;
[Inject]
public var event:DataEvent;
override public function execute() : void
{
trace("PopulateModelCommand, model=" + model);
model.test();
//model.gallery = event.gallery;
}
}
the model gets injected (I get a trace model=[object BPModel] but when I try and access any of the model's properties/methods I get a compiler error PopulateModelCommand.as(23): col: 10 Error: Call to a possibly undefined method test.
model.test();
Both BPModel and XMLLocalService extend Actor. Why can I access the methods in a service but can't in my model? What am I doing wrong?
I am using RL swc 1.3.0. My compiler is set to keep [Inject] and [PostConstruct]. Below is the full stack I am getting when I am trying to compile the project.
mxmlc -load-config+=obj\BPLandingPageConfig.xml -debug=true -incremental=true -benchmark=false -keep-as3-metadata+=Inject -keep-as3-metadata+=PostConstruct -o obj\BPLandingPage634210368560312500
Incremental compile of 1
Loading configuration file C:\Program Files\Flex3SDK\frameworks\flex-config.xml
Loading configuration file ... BPLandingPageConfig.xml
Recompile: ... BPLandingPageContext.as
Reason: The source file or one of the included files has been updated.
Recompile: ...PopulateModelCommand.as
Reason: The source file or one of the included files has been updated.
Files changed: 2 Files affected: 0
(fcsh)
... PopulateModelCommand.as(23): col: 10 Error: Call to a possibly undefined method test.
model.test();
^
Build halted with errors (fcsh).
Done (1)
Many thanks for your help in advance.
- src.zip 5.69 KB
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
Support Staff 1 Posted by Ondina D.F. on 26 Sep, 2010 02:13 PM
Hi Igor,
It’s a name collision ( var model and package name model ):
import model.IBPModel;
and
[Inject] public var model:IBPModel;
Try to change the var model to something else, say
public var bpModel: IBPModel;
and it will work.
Ondina
Support Staff 2 Posted by Ondina D.F. on 26 Sep, 2010 02:16 PM
And don’t call test() in the constructor:
public function BPModel()
{ test();
}
Ondina
3 Posted by Igor on 26 Sep, 2010 02:21 PM
Ondina. Amazing, thank you so much. What was confusing me is that when I was tracing the model I was given the right type model=[object BPModel] which led me to believe I was dealing with the right object and no name collision was happening.
Igor
4 Posted by Igor on 26 Sep, 2010 02:22 PM
Btw. When I was calling test() in the constructor it would fire OK as I expected.
Stray closed this discussion on 10 Feb, 2011 05:51 PM.