trouble understanding event injection as seen in robotlegs.demos.flashgooglemaps

%'s Avatar

%

24 Jan, 2010 11:13 PM

public class GeoCodingCommand extends Command
{
    [Inject]
    public var service:GeoCodingService;

    [Inject]
    public var event:SystemEvent;
    //--------------------------------------------------------------------------
    //
    //  Overridden API
    //
    //--------------------------------------------------------------------------
    override public function execute():void
    {
        service.requestGeocoding(event.body.city, event.body.address);
    }
}

I do not understand how the code from 'robotlegs.demos.flashgooglemaps' seen above avoids throwing this Error:

        Injector is missing a rule to handle injection into target ...

My similar code throws the above Error unless I include something like:

        var event:SystemEvent = new SystemEvent(SystemEvent.CONSTANT);
        injector.mapValue(SystemEvent, event);
  1. Support Staff 1 Posted by Shaun Smith on 24 Jan, 2010 11:35 PM

    Shaun Smith's Avatar

    The CommandMap sets up a temporary rule that maps the event (by it's concrete class) for injection just before execute() is called:

    http://github.com/robotlegs/robotlegs-framework/blob/master/src/org...

    The injection must be exactly the same event class that triggers the Command. So, if this triggers the command:

    dispatch(new CrazyEvent(CrazyEvent.BOOM));
    

    The injection in the command must be specified like this:

    [Inject] public var event:CrazyEvent;
    

    This will not work:

    [Inject] public var event:Event;
    

    Hope that helps. Let me know if you're still getting an error.

  2. 2 Posted by % on 25 Jan, 2010 10:02 AM

    %'s Avatar

    thanks much for your explanation.

    my code now works, but I had to:
    commandMap.mapEvent(ModelEvent.REQUEST_LOAD, RequestLoadCommand, ModelEvent);
    via:
    dispatchEvent(new ContextEvent(ContextEvent.STARTUP));

    previously I had this in my Context::startup:
    commandMap.mapEvent(ModelEvent.REQUEST_LOAD, RequestLoadCommand, ModelEvent);
    super.startup();

    ... somehow the mapping needs to be done in response to ContextEvent.STARTUP rather than Context.startup

  3. Till Schneidereit closed this discussion on 02 Mar, 2010 12:46 PM.

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