Injection doesn't appear to be working
Hello,
I'm having a bit of a problem getting RL to work, it appears my injection is not working properly. I'm building a Flash application (edit : I've just seen this post - http://knowledge.robotlegs.org/discussions/questions/89-flash-cs4-c... - this might be the cause...), below is how far I've got:
Document Class:
`package
{
import com.myProject.MyContext;
import flash.display.MovieClip;
public class MyMain extends MovieClip
{
protected var context : MyContext;
public function MyMain()
{
context = new MyContext(this);
}
}
} `
Context:
` package com.myProject
{
import com.myProject.controller.StartupCommand;
import com.myProject.model.services.XMLLoader;
import org.robotlegs.base.ContextEvent;
import org.robotlegs.mvcs.Context;
import flash.display.DisplayObjectContainer;
public class MyContext extends Context
{
public function MyContext(contextView : DisplayObjectContainer)
{
super(contextView);
}
override public function startup() : void
{
trace("startup");
injector.mapSingleton(XMLLoader);
//This Context is mapping a single command to the ContextEvent.STARTUP
//The StartupCommand will map additional commands, mediators, services,
//and models for use in the application.
commandMap.mapEvent(ContextEvent.STARTUP, StartupCommand, ContextEvent, true);
//Start the Application (triggers the StartupCommand)
dispatchEvent(new ContextEvent(ContextEvent.STARTUP));
}
}
} `
StartupCommand
` package com.myProject.controller
{
import com.swatch.model.services.XMLLoader;
import org.robotlegs.mvcs.Command;
public class StartupCommand extends Command
{
[Inject]
public var xmlLoader : XMLLoader;
override public function execute() : void
{
// xmlLoader.startLoading();
trace("*** xmlLoader *** : " + (xmlLoader)); // THIS RETURNS NULL...
}
}
} `
XMLLoader:
` package com.myProject.model.services
{
import org.robotlegs.mvcs.Actor;
/**
* @author alexstanbury
*/
public class XMLLoader extends Actor
{
public function XMLLoader()
{
}
public function startLoading() : void
{
trace("start loading the xml in");
}
}
} `
As you can see, I can get into the execute function of the command but it returns null for the injection of the XMLLoader. I am using latest RL .swc
Any ideas?
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 Shaun Smith on 08 Apr, 2010 08:35 AM
Hi,
What are you using to compile your app?
2 Posted by x0b on 08 Apr, 2010 09:25 AM
Hi Shaun,
I was using CS4, and realised from reading that thread mentioned in my previous post that the CS3/4 compiler strips out metadata.
So I have converted my project to use the flex compiler, and am using an asset.swc to access movieclips etc.
I looked at the XML workaround but it seems a bit longwinded.
Support Staff 3 Posted by Shaun Smith on 08 Apr, 2010 09:58 AM
Hi Alex,
Yes, unfortunately CS3/4 does strip out the metadata, and the XML workaround is quite verbose. Compiling with MXMLC and including assets via SWC files is definitely the recommended approach.
4 Posted by x0b on 08 Apr, 2010 10:13 AM
cool, glad i'm on the right track, thanks :)
x0b closed this discussion on 21 Sep, 2010 11:36 AM.