No se puede enviar el evento desde el modelo

using robotlegs i always retrieve this error. I have not idea whats wrong.

TypeError: Error #1009: Cannot access a property or method of a null object reference. at org.robotlegs.mvcs::Actor/dispatch()[/Users/shaun/Documents/ Development/Workspaces/GanymedeFB4/robotlegs-framework/src/org/ robotlegs/mvcs/]


package com.something.model {
    // someimports
    public class PhotoModel extends Actor {

        public function uploadAndDetect() : void {  
            // something        
            dispatch(new DetectEvent(DetectEvent.DETECTED));                



package {
    // someimports

    public class DetectEvent extends Event {
        public static const DETECTED : String = "DETECTED";

        public function DetectEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false){
            super(type, bubbles, cancelable);

        override public function clone():Event{
            return new DetectEvent(type, bubbles, cancelable);

preguntado el 08 de noviembre de 11 a las 14:11

What does line 97 say on -

Note that you don't need to create a custom Event just to declare a new Event constant. Unless you're carrying a payload other than type, you're probably better off just creating a Class that lists out your event Constants as static members. -

@joncys: is part of the robotlegs framework -

@AmyBlankenship Thanks. I know this. -

2 Respuestas

I can't read German well enough to be sure, but I'd suspect that the issue is that your Model isn't getting injected with the Event Bus (IEventDispatcher shared by just about everything Robotlegs needs to communicate with).

How are you instantiating this? Are you running this from a Unit test? If so, you need to set the eventDispatcher on your Model. If not, you need to use mapClass, mapSingleton, or mapSingletonOf to make sure your Model gets instantiated with the things it needs to work as an Actor.

respondido 08 nov., 11:19

I do this in my context: injector.mapSingleton(PhotoModel); - Fabian

Amy is right, it will have something to do with the EventDispatcher not being initialized. You are probably dispatching the model event before your context finished loading. - Dennis Jaamann

Fabian, just to check... the only way you are instantiating your model is allowing the Injector to create it, correct? - Amy Blankenship

Is uploadAndDetect called in the constructor of the model? - Creynders

When and where are creating the Model? I bet that your are not injecting its dependencies. The model should be created in a Command and the use:

var model: PhotoModel = new PhotoModel();

And then the eventDispatcher (the only dependency of Actor) should be injected.

Respondido 04 Abr '12, 22:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.