forwarding custom events from view

andreas's Avatar

andreas

30 Nov, 2011 12:06 PM

I have some events that i dispatch in my view, now I also want to use this custom events outside of the view in a command.
What I came up with is a forward function, that dispatches the event again:
my Mediator:

    public override function onRegister():void {
        addViewListener( SomeEvent.TYPE, forward )
        addViewListener( SomeOtherEvent.TYPE, forward )
        ...
    }

    public function forward(e:Event):void {
        dispatch(e.clone())
    }

this works, but seems kinda wrong.
So, is this best practice or how would you "forward" these events?
Or should I listen to the flash-events that the gui throws (mostly MouseEvent.CLICK...) and create my events in the mediator (which means I need to put some more logic in the mediator which also feels wrong)?

  1. 1 Posted by krasimir on 30 Nov, 2011 12:19 PM

    krasimir's Avatar

    Hello andreas,

    What you have to do is:
    addViewListener( SomeEvent.TYPE, dispatch)
    I.e. you don't need this forward method. Just pass the dispatch method as a handler.

    And have in mind that you should override the clone method in your custom events.

  2. 2 Posted by andreas on 01 Dec, 2011 02:32 PM

    andreas's Avatar

    hi krasimir,

    Thank you very much, your suggestion works great!

    Thread closed.

  3. andreas closed this discussion on 01 Dec, 2011 02:32 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