What is wrong whith this approach?

Fernando's Avatar


25 Oct, 2012 09:17 AM

I suspect that i´m suffering a deep misconception with RL and DI.
I´m trying to launch a simple test, without employing Actors, Mediators etc, only one class, one context and a application.
I have a Class:

public class MyClass {
    public function MyClass() {

    public function echo(input:String):String {
        return "echo " + input;

That i´m mapping in my context:

import org.robotlegs.mvcs.Context;

public class MyContext extends Context {
    public function MyContext() {

    override public function startup():void {
        var myClassInstance:MyClass = new MyClass();
        injector.mapValue(MyClass, myClassInstance);



And I want to inject MyClass in my Application, and use it with her simple method "echo":

        import misc.MyClass;
        import mx.controls.Alert;

        public var myInstance:MyClass;

        protected function button1_clickHandler(event:MouseEvent):void {

    <misc:MyContext contextView="{this}"/>

<s:Group width="100%" height="100%">
    <s:Button width="100" height="24" label="prueba"

The problem is that the injection not occur... when I press the button myInstance is null.
I also tested to use mapSingleton in the context (and many others combinations).
I´m using FlashBuilder, and I added the aditional compiler arguments to use the metatags
Inject, later I deleted because I´m using the robotlegs SWC directly.
I reviewed the faqs, the ActionScript Developer's Guide to Robotlegs, and many webs, and I don´t
understand where is the failure.
On the other hand... I created another project using, mediators, actors, etc (the RL architecture) and
I everything works ok. Only I have one problem with this simple case.

I Have a misconception with how works DI with swifsuspenders/robotlegs or I had another problem
with librarys, metatags ?

p.d I attach the simple project file

  1. 1 Posted by Fernando on 25 Oct, 2012 09:35 AM

    Fernando's Avatar

    Sorry. I´m using RobotLegs 1.5 and Flex SDK 4.6

  2. 2 Posted by neil on 25 Oct, 2012 09:58 AM

    neil's Avatar

    ok, just a quick look at your code above (but not the attached project) and I would say that the reason for failure is that to fulfil the injection points the Application will have to be created by, or at leased be injectInto() by the Injector. Since it is the Main Application, by its nature it will be the first thing created, so you will have to manually injectInto

    I think that in the Context you will have to:

     override public function startup():void {
            var myClassInstance:MyClass = new MyClass();
            injector.mapValue(MyClass, myClassInstance);
            injector.injectInto( contextView );

    That should do it

  3. 3 Posted by Fernando on 25 Oct, 2012 10:02 AM

    Fernando's Avatar

    Yes Neil, that is the problem. I have no words to express my gratitude. Thanks

  4. 4 Posted by neil on 25 Oct, 2012 10:16 AM

    neil's Avatar

    then please express yourself in a dance form of your choosing.

  5. Support Staff 5 Posted by Ondina D.F. on 25 Oct, 2012 02:30 PM

    Ondina D.F.'s Avatar

    Fernando, may I close this thread, or are you still dancing? ;-)

  6. 6 Posted by Fernando Diaz G... on 25 Oct, 2012 02:45 PM

    Fernando Diaz Garcia's Avatar

    close please. I' m too tired of play the corn's dance
    El 25/10/2012 16:31, "Ondina D.F." <
    [email blocked]> escribió:

  7. Support Staff 7 Posted by Ondina D.F. on 25 Oct, 2012 03:01 PM

    Ondina D.F.'s Avatar

    Haha, ok.

  8. Ondina D.F. closed this discussion on 25 Oct, 2012 03:01 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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