Null eventDispatcher in Model

John P's Avatar

John P

08 Apr, 2013 02:53 AM

New to the framework as a whole. I'm trying to dispatch events from my model, but my eventDispatcher is not being mapped.

public function SphereConfig():void
            _spherModel = new SphereModel();
        public function configure():void
            var _model:SphereModel = new SphereModel();

  , SphereEvent).toCommand(SphereCommand);

//Model Code
    import flash.geom.Point;
    import robotlegs.bender.extensions.localEventMap.api.IEventMap;
    public class SphereModel extends EventDispatcher
        private var _locations:Array = [];
        public var currentIndex:int;
        public var currentPoint:Point;
        public var eventMap:IEventMap;
        public var eventDispatcher:IEventDispatcher;
        public function SphereModel()
            _locations.push( new Point(10, 10) );
            _locations.push( new Point(50, 50) );
            _locations.push( new Point(100, 100) );
            _locations.push( new Point(150, 150) );
            _locations.push( new Point(200, 200) );
        public function setActivePoint(index:int):void
            index = index < _locations.length ? index : 0;
            currentIndex = index;
            currentPoint = _locations[currentIndex];
            eventDispatcher.dispatchEvent(new SphereEvent(SphereEvent.CHANGE, currentPoint) ); // eventDispatcher is null ....

The rest of my test component is working correctly, commands, mediators, context classes. I'm not sure why eventDispatcher is null in the model.

  1. 1 Posted by John P on 08 Apr, 2013 03:20 AM

    John P's Avatar

    I've simplified it down to the following in my config file: new SphereModel() );

    I see the super being called only once, but when setActivePoint is called in a different command class, eventDispatcher is still null

  2. Support Staff 2 Posted by Ondina D.F. on 08 Apr, 2013 07:29 AM

    Ondina D.F.'s Avatar

    Hello John,

    That’s because you are instantiating the model yourself:
    var _model:SphereModel = new SphereModel();

    You need to let the injector create an instance of a class that requires an injection.
    You can use one of the following mappings:



    var anotherModel:AnotherModel = injector.instantiateUnmapped(AnotherModel);;


    var anotherModel:AnotherModel = new AnotherModel();;


    var anotherModel:AnotherModel = injector.getOrCreateNewInstance(AnotherModel);;

    Does this help?


  3. 3 Posted by John P on 08 Apr, 2013 01:16 PM

    John P's Avatar

    Thanks Ondina. That works great. I feel like i'm lacking on information on how injection works. Is there documentation for SwiftSuspsenders 2.0? Their wiki on github seems to be a bit lacking.

    I'll probably be back with more questions - RL seems to be a great framework to standardize object communication.

  4. Support Staff 4 Posted by Ondina D.F. on 08 Apr, 2013 03:44 PM

    Ondina D.F.'s Avatar

    No problem, John!

    Hmm, you’re right, the SwiftSuspsenders 2.0 documentation is not ideal.
    But since you’re using robotlegs 2, maybe you could walk through its documentation on github and also through the examples on this forum to learn how to use the injector for various situations.
    And, of course, come back to the forum with questions, whenever you need assistance!!!

    rl2 start here:

    and inspect every package to find the readme files..

    I’m going to close this thread. You can reopen it, if need be.


  5. Ondina D.F. closed this discussion on 08 Apr, 2013 03:44 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