Mediator dispatching en event, however Command is not called

jansensan's Avatar

jansensan

11 Nov, 2011 06:39 PM

I have a weird issue, one of my events, event though it is mapped to a command in the context, does not function. Let me explain my flow briefly.

I have a MapEditorContext, in which I map the event:

commandMap.mapEvent (   MapEditorEvent.TILESET_SELECTION_CHANGE,
                        SetSelectedTilesetCommand, 
                        MapEditorEvent, 
                        false
                    );

In the TilesetsMediator, there is a point where the event is dispatched:

private function redispatchEventHandler(event:MapEditorEvent):void
{
    trace("\n", this, "---  redispatchEventHandler  ---");

    trace("\t", "event: " + (event));
    // traces event: [Event type="TILESET_SELECTION_CHANGE" bubbles=false cancelable=false eventPhase=2]

    trace("\t", "event is MapEditorEvent: " + (event is MapEditorEvent));
    // traces event is MapEditorEvent: true

    dispatch(event);
}

On the side of the SetSelectedTilesetCommand, it seems like it's never called at all...

override public function execute():void
{
    trace("\n", this, "---  execute  ---");

    // event sent from Tilesets.comboBoxChangeHandler()
    tilesetsModel.setSelectedTileset(event.data as String);
}

Other events and commands work properly in the project, so I am wondering where I should start looking really... If anyone could help, it would be greatly appreciated!

  1. 1 Posted by krasimir on 11 Nov, 2011 07:03 PM

    krasimir's Avatar

    Hello,
    1. Basically you can add the "dispatch" method as a handler function of your events (in the mediator. I mean there is no need to have redispatchEventHandler type of functions, except if you want to debug something.
    2. Check if the mapping of the event to the command is made after the dispatching of the event in the mediator.

  2. Support Staff 2 Posted by Ondina D.F. on 11 Nov, 2011 07:10 PM

    Ondina D.F.'s Avatar

    Hi Jansen,
    “On the side of the SetSelectedTilesetCommand, it seems like it's never called at all...”
    Does this mean that your Command has been executed?
    Can you see the first trace in your SetSelectedTilesetCommand.execute() method?
    If the answer is yes, then next question is:

    Have you injected the event into your command?
    You can't access the payload of your event if you didn't inject it into the command.

    Let us know if it still doesn't work after injecting the event or if that wasn't the issue.

    Ondina

  3. 3 Posted by jansensan on 11 Nov, 2011 07:23 PM

    jansensan's Avatar

    @ krasimir: I'll answer to your points in numbers, like you did ;) 1. Nice trick, I did not think of it this way, I'll do that in the future.
    2. The mapping happens before I call my view.init(). See the output below:

    [object TilesetsMediator] ---  onRegister  ---
    
    [object Tilesets] ---  init  ---
    [Loading] Loaded: SpriteQuestMapEditor.swf
    
    [object TilesetsMediator] ---  spritesheetsLoadedHandler  ---
    
    [object Tilesets] ---  comboBoxChangeHandler  ---
         eventToDispatch: [Event type="SPRITESHEET_SELECTION_CHANGE" bubbles=false cancelable=false eventPhase=2]
    
    [object TilesetsMediator] ---  tilesetsLoadedHandler  ---
    
    [object Tilesets] ---  comboBoxChangeHandler  ---
         eventToDispatch: [Event type="TILESET_SELECTION_CHANGE" bubbles=false cancelable=false eventPhase=2]
    

    @ Ondina D.F.: I mean that I never see the trace. Concerning the event, yes I inject it. Below is the full command:

    package spritequest.mapeditor.controller
    {
        import spritequest.mapeditor.event.MapEditorEvent;
        import spritequest.mapeditor.model.TilesetsModel;
    
        import org.robotlegs.mvcs.Command;
    
    
        /**
         * @author Mat Janson Blanchet
         */
        public class SetSelectedTilesetCommand extends Command
        {
            // + ----------------------------------------
            //      [ VARIABLES ]
            // + ----------------------------------------
    
            [Inject]
            public  var tilesetsModel   :TilesetsModel;
    
            [Inject]
            public  var event   :MapEditorEvent;
    
    
            // + ----------------------------------------
            //      [ PUBLIC METHODS ]
            // + ----------------------------------------
    
            override public function execute():void
            {
                trace("\n", this, "---  execute  ---");
    
                // event sent from Tilesets.comboBoxChangeHandler()
                tilesetsModel.setSelectedTileset(event.data as String);
            }
    
    
        }
    }
    
  4. Support Staff 4 Posted by Ondina D.F. on 11 Nov, 2011 07:24 PM

    Ondina D.F.'s Avatar

    Adding another possibility:

    In your MapEditorEvent class you need to override clone()
    override public function clone():Event
    { return new MapEditorEvent (type, payload, bubbles, cancelable); } Did you do that?

  5. 5 Posted by jansensan on 11 Nov, 2011 07:28 PM

    jansensan's Avatar

    That's an interesting point! I recently created an AbstractDataEvent class in which I moved that there, let me test that!

  6. Support Staff 6 Posted by Ondina D.F. on 11 Nov, 2011 07:32 PM

    Ondina D.F.'s Avatar

    It should look like so:
    public function SomeEvent(type:String, payload:String, bubbles:Boolean=false, cancelable:Boolean=false)
    {

    _payload=payload;
    super(type, bubbles, cancelable);
    }

    override public function clone():Event
    {

    return new SomeEvent(type, payload, bubbles, cancelable);

    }

    private var _payload:String;

    public function get payload():String
    {

    return _payload;

    }

  7. Support Staff 7 Posted by Ondina D.F. on 11 Nov, 2011 07:34 PM

    Ondina D.F.'s Avatar

    "That's an interesting point! I recently created an AbstractDataEvent class in which I moved that there, let me test that!" o.k.
    I have to go now. Krasimir will take it from here:)

  8. 8 Posted by jansensan on 11 Nov, 2011 07:35 PM

    jansensan's Avatar

    Brilliant! That was exactly the issue here! Thanks so much for thinking of that stuff!

  9. 9 Posted by krasimir on 11 Nov, 2011 07:56 PM

    krasimir's Avatar

    You are welcome ;)

  10. Support Staff 10 Posted by Ondina D.F. on 13 Nov, 2011 08:39 AM

    Ondina D.F.'s Avatar

    You’re welcome, indeed!
    Ondina
    [ Feel free to reopen this discussion in case you have more questions or you need further assistance with this issue. Please open new threads for new issues. ]

  11. Ondina D.F. closed this discussion on 13 Nov, 2011 08:39 AM.

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