Null eventDispatcher in Model
Howdy,
New to the framework as a whole. I'm trying to dispatch events from
my model, but my eventDispatcher is not being mapped.
//CONFIG CODE
public function SphereConfig():void
{
_spherModel = new SphereModel();
}
public function configure():void
{
var _model:SphereModel = new SphereModel();
context.injector.map(SphereModel).toValue(_model);
eventCommandMap.map(SphereEvent.GOTO_NEXT_POINT, SphereEvent).toCommand(SphereCommand);
mediator.map(IMoveTo).toMediator(SphereMediator);
context.afterInitializing(init);
}
//Model Code
package com.me.loading.loadingtypes.sphere
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
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;
[Inject]
public var eventMap:IEventMap;
[Inject]
public var eventDispatcher:IEventDispatcher;
public function SphereModel()
{
super();
_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.
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
1 Posted by John P on 08 Apr, 2013 03:20 AM
I've simplified it down to the following in my config file:
I see the super being called only once, but when setActivePoint is called in a different command class, eventDispatcher is still null
Support Staff 2 Posted by Ondina D.F. on 08 Apr, 2013 07:29 AM
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:
1.
2.
3.
4.
Does this help?
Ondina
3 Posted by John P on 08 Apr, 2013 01:16 PM
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.
Support Staff 4 Posted by Ondina D.F. on 08 Apr, 2013 03:44 PM
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:
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...
and inspect every package to find the readme files..
I’m going to close this thread. You can reopen it, if need be.
Cheers,
Ondina
Ondina D.F. closed this discussion on 08 Apr, 2013 03:44 PM.